nushell/crates/nu-cli/tests/completions/mod.rs

1213 lines
38 KiB
Rust
Raw Normal View History

pub mod support;
use nu_cli::NuCompleter;
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{debugger::WithoutDebug, engine::StateWorkingSet, PipelineData};
use reedline::{Completer, Suggestion};
use rstest::{fixture, rstest};
use std::{
path::{PathBuf, MAIN_SEPARATOR},
sync::Arc,
};
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
use support::{
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
completions_helpers::{new_dotnu_engine, new_partial_engine, new_quote_engine},
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
file, folder, match_suggestions, new_engine,
};
#[fixture]
fn completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = "def tst [--mod -s] {}";
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
}
#[fixture]
fn completer_strings() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"def animals [] { ["cat", "dog", "eel" ] }
def my-command [animal: string@animals] { print $animal }"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
}
#[fixture]
fn extern_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"
def animals [] { [ "cat", "dog", "eel" ] }
extern spam [
animal: string@animals
--foo (-f): string@animals
-b: string@animals
]
"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
}
#[fixture]
fn custom_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"
let external_completer = {|spans|
$spans
}
$env.config.completions.external = {
enable: true
max_results: 100
completer: $external_completer
}
"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
}
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
#[fixture]
fn subcommand_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Use fuzzy matching, because subcommands are sorted by Levenshtein distance,
// and that's not very useful with prefix matching
let commands = r#"
$env.config.completions.algorithm = "fuzzy"
def foo [] {}
def "foo bar" [] {}
def "foo abaz" [] {}
def "foo aabrr" [] {}
def food [] {}
"#;
assert!(support::merge_input(commands.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
}
#[test]
fn variables_dollar_sign_with_varialblecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "$ ";
let suggestions = completer.complete(target_dir, target_dir.len());
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
assert_eq!(8, suggestions.len());
}
#[rstest]
fn variables_double_dash_argument_with_flagcompletion(mut completer: NuCompleter) {
let suggestions = completer.complete("tst --", 6);
let expected: Vec<String> = vec!["--help".into(), "--mod".into()];
// dbg!(&expected, &suggestions);
match_suggestions(expected, suggestions);
}
#[rstest]
fn variables_single_dash_argument_with_flagcompletion(mut completer: NuCompleter) {
let suggestions = completer.complete("tst -", 5);
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn variables_command_with_commandcompletion(mut completer_strings: NuCompleter) {
let suggestions = completer_strings.complete("my-c ", 4);
let expected: Vec<String> = vec!["my-command".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn variables_subcommands_with_customcompletion(mut completer_strings: NuCompleter) {
let suggestions = completer_strings.complete("my-command ", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn variables_customcompletion_subcommands_with_customcompletion_2(
mut completer_strings: NuCompleter,
) {
let suggestions = completer_strings.complete("my-command ", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[test]
fn dotnu_completions() {
// Create a new engine
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
let (_, _, engine, stack) = new_dotnu_engine();
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
let expected = vec![
"asdf.nu".into(),
"bar.nu".into(),
"bat.nu".into(),
"baz.nu".into(),
#[cfg(windows)]
"dir_module\\".into(),
#[cfg(not(windows))]
"dir_module/".into(),
"foo.nu".into(),
"spam.nu".into(),
"xyzzy.nu".into(),
];
// Test source completion
let completion_str = "source-env ".to_string();
let suggestions = completer.complete(&completion_str, completion_str.len());
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
match_suggestions(expected.clone(), suggestions);
// Test use completion
let completion_str = "use ".to_string();
let suggestions = completer.complete(&completion_str, completion_str.len());
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
match_suggestions(expected.clone(), suggestions);
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
// Test overlay use completion
let completion_str = "overlay use ".to_string();
let suggestions = completer.complete(&completion_str, completion_str.len());
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
match_suggestions(expected, suggestions);
}
#[test]
#[ignore]
fn external_completer_trailing_space() {
// https://github.com/nushell/nushell/issues/6378
let block = "{|spans| $spans}";
let input = "gh alias ".to_string();
let suggestions = run_external_completion(block, &input);
assert_eq!(3, suggestions.len());
Apply nightly clippy fixes (#11083) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Clippy fixes for rust 1.76.0-nightly # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> N/A # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-11-17 16:15:55 +01:00
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("alias", suggestions.get(1).unwrap().value);
assert_eq!("", suggestions.get(2).unwrap().value);
}
#[test]
fn external_completer_no_trailing_space() {
Let with pipeline (#9589) # Description This changes the default behaviour of `let` to be able to take a pipeline as its initial value. For example: ``` > let x = "hello world" | str length ``` This is a change from the existing behaviour, where the right hand side is assumed to be an expression. Pipelines are more general, and can be more powerful. My google foo is failing me, but this also fixes this issue: ``` let x = foo ``` Currently, this reads `foo` as a bareword that gets converted to a string rather than running the `foo` command. In practice, this is really annoying and is a really hard to spot bug in a script. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE `let` gains the power to be assigned via a pipeline. However, this changes the behaviour of `let x = foo` from assigning the string "foo" to `$x` to being "run the command `foo` and give the result to `$x`" # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-07-03 07:45:10 +02:00
let block = "{|spans| $spans}";
let input = "gh alias".to_string();
let suggestions = run_external_completion(block, &input);
assert_eq!(2, suggestions.len());
Apply nightly clippy fixes (#11083) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Clippy fixes for rust 1.76.0-nightly # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> N/A # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-11-17 16:15:55 +01:00
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("alias", suggestions.get(1).unwrap().value);
}
#[test]
fn external_completer_pass_flags() {
Let with pipeline (#9589) # Description This changes the default behaviour of `let` to be able to take a pipeline as its initial value. For example: ``` > let x = "hello world" | str length ``` This is a change from the existing behaviour, where the right hand side is assumed to be an expression. Pipelines are more general, and can be more powerful. My google foo is failing me, but this also fixes this issue: ``` let x = foo ``` Currently, this reads `foo` as a bareword that gets converted to a string rather than running the `foo` command. In practice, this is really annoying and is a really hard to spot bug in a script. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE `let` gains the power to be assigned via a pipeline. However, this changes the behaviour of `let x = foo` from assigning the string "foo" to `$x` to being "run the command `foo` and give the result to `$x`" # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-07-03 07:45:10 +02:00
let block = "{|spans| $spans}";
let input = "gh api --".to_string();
let suggestions = run_external_completion(block, &input);
assert_eq!(3, suggestions.len());
Apply nightly clippy fixes (#11083) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Clippy fixes for rust 1.76.0-nightly # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> N/A # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-11-17 16:15:55 +01:00
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("api", suggestions.get(1).unwrap().value);
assert_eq!("--", suggestions.get(2).unwrap().value);
}
#[test]
fn file_completions() {
// Create a new engine
let (dir, dir_str, engine, stack) = new_engine();
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Test completions for the current folder
Migrate to a new PWD API (#12603) This is the first PR towards migrating to a new `$env.PWD` API that returns potentially un-canonicalized paths. Refer to PR #12515 for motivations. ## New API: `EngineState::cwd()` The goal of the new API is to cover both parse-time and runtime use case, and avoid unintentional misuse. It takes an `Option<Stack>` as argument, which if supplied, will search for `$env.PWD` on the stack in additional to the engine state. I think with this design, there's less confusion over parse-time and runtime environments. If you have access to a stack, just supply it; otherwise supply `None`. ## Deprecation of other PWD-related APIs Other APIs are re-implemented using `EngineState::cwd()` and properly documented. They're marked deprecated, but their behavior is unchanged. Unused APIs are deleted, and code that accesses `$env.PWD` directly without using an API is rewritten. Deprecated APIs: * `EngineState::current_work_dir()` * `StateWorkingSet::get_cwd()` * `env::current_dir()` * `env::current_dir_str()` * `env::current_dir_const()` * `env::current_dir_str_const()` Other changes: * `EngineState::get_cwd()` (deleted) * `StateWorkingSet::list_env()` (deleted) * `repl::do_run_cmd()` (rewritten with `env::current_dir_str()`) ## `cd` and `pwd` now use logical paths by default This pulls the changes from PR #12515. It's currently somewhat broken because using non-canonicalized paths exposed a bug in our path normalization logic (Issue #12602). Once that is fixed, this should work. ## Future plans This PR needs some tests. Which test helpers should I use, and where should I put those tests? I noticed that unquoted paths are expanded within `eval_filepath()` and `eval_directory()` before they even reach the `cd` command. This means every paths is expanded twice. Is this intended? Once this PR lands, the plan is to review all usages of the deprecated APIs and migrate them to `EngineState::cwd()`. In the meantime, these usages are annotated with `#[allow(deprecated)]` to avoid breaking CI. --------- Co-authored-by: Jakub Žádník <kubouch@gmail.com>
2024-05-03 13:33:09 +02:00
let target_dir = format!("cp {dir_str}{MAIN_SEPARATOR}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
folder(dir.join("another")),
file(dir.join("custom_completion.nu")),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
folder(dir.join("directory_completion")),
file(dir.join("nushell")),
folder(dir.join("test_a")),
folder(dir.join("test_b")),
file(dir.join(".hidden_file")),
folder(dir.join(".hidden_folder")),
];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completions for a file
let target_dir = format!("cp {}", folder(dir.join("another")));
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![file(dir.join("another").join("newfile"))];
// Match the results
match_suggestions(expected_paths, suggestions);
Fix completions for directories with hidden files (#11921) # Description Attempting to complete a directory with hidden files could cause a variety of issues. When Rust parses the partial path to be completed into components, it removes the trailing `.` since it interprets this to mean "the current directory", but in the case of the completer we actually want to treat the trailling `.` as a literal `.`. This PR fixes this by adding a `.` back into the Path components if the last character of the path is a `.` AND the path is longer than 1 character (eg., not just a ".", since that correctly gets interpreted as Component::CurDir). Here are some things this fixes: - Panic when tab completing for hidden files in a directory with hidden files (ex. `ls test/.`) - Panic when tab completing a directory with only hidden files (since the common prefix ends with a `.`, causing the previous issue) - Mishandling of tab completing hidden files in directory (ex. `ls ~/.<TAB>` lists all files instead of just hidden files) - Trailing `.` being inexplicably removed when tab completing a directory without hidden files While testing for this PR I also noticed there is a similar issue when completing with `..` (ex. `ls ~/test/..<TAB>`) which is not fixed by this PR (edit: see #11922). # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> N/A # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Added a hidden-files-within-directories test to the `file_completions` test. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-02-26 19:14:19 +01:00
// Test completions for hidden files
let target_dir = format!("ls {}/.", folder(dir.join(".hidden_folder")));
let suggestions = completer.complete(&target_dir, target_dir.len());
let expected_paths: Vec<String> =
vec![file(dir.join(".hidden_folder").join(".hidden_subfile"))];
// Match the results
match_suggestions(expected_paths, suggestions);
}
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
#[test]
fn partial_completions() {
// Create a new engine
let (dir, _, engine, stack) = new_partial_engine();
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
// Test completions for a folder's name
let target_dir = format!("cd {}", file(dir.join("pa")));
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
folder(dir.join("partial")),
folder(dir.join("partial-a")),
folder(dir.join("partial-b")),
folder(dir.join("partial-c")),
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completions for the files whose name begin with "h"
// and are present under directories whose names begin with "pa"
let dir_str = file(dir.join("pa").join("h"));
let target_dir = format!("cp {dir_str}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
file(dir.join("partial").join("hello.txt")),
file(dir.join("partial-a").join("have_ext.exe")),
file(dir.join("partial-a").join("have_ext.txt")),
file(dir.join("partial-a").join("hello")),
file(dir.join("partial-a").join("hola")),
file(dir.join("partial-b").join("hello_b")),
file(dir.join("partial-b").join("hi_b")),
file(dir.join("partial-c").join("hello_c")),
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completion for all files under directories whose names begin with "pa"
let dir_str = folder(dir.join("pa"));
let target_dir = format!("ls {dir_str}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
file(dir.join("partial").join("hello.txt")),
file(dir.join("partial-a").join("anotherfile")),
file(dir.join("partial-a").join("have_ext.exe")),
file(dir.join("partial-a").join("have_ext.txt")),
file(dir.join("partial-a").join("hello")),
file(dir.join("partial-a").join("hola")),
file(dir.join("partial-b").join("hello_b")),
file(dir.join("partial-b").join("hi_b")),
file(dir.join("partial-c").join("hello_c")),
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completion for a single file
let dir_str = file(dir.join("fi").join("so"));
let target_dir = format!("rm {dir_str}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![file(dir.join("final_partial").join("somefile"))];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completion where there is a sneaky `..` in the path
let dir_str = file(dir.join("par").join("..").join("fi").join("so"));
let target_dir = format!("rm {dir_str}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
fix: prevent relative directory traversal from crashing (#12438) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> - fixes #11922 - fixes #12203 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This is a rewrite for some parts of the recursive completion system. The Rust `std::path` structures often ignores things like a trailing `.` because for a complete path, it implies the current directory. We are replacing the use of some of these structs for Strings. A side effect is the slashes being normalized in Windows. For example if we were to type `foo/bar/b`, it would complete it to `foo\bar\baz` because a backward slash is the main separator in windows. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Relative paths are preserved. `..`s in the paths won't eagerly show completions from the parent path. For example, `asd/foo/../b` will now complete to `asd/foo/../bar` instead of `asd/bar`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-04 03:17:50 +02:00
let expected_paths: Vec<String> = vec![
file(
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
dir.join("partial")
.join("..")
.join("final_partial")
.join("somefile"),
),
file(
dir.join("partial-a")
fix: prevent relative directory traversal from crashing (#12438) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> - fixes #11922 - fixes #12203 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This is a rewrite for some parts of the recursive completion system. The Rust `std::path` structures often ignores things like a trailing `.` because for a complete path, it implies the current directory. We are replacing the use of some of these structs for Strings. A side effect is the slashes being normalized in Windows. For example if we were to type `foo/bar/b`, it would complete it to `foo\bar\baz` because a backward slash is the main separator in windows. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Relative paths are preserved. `..`s in the paths won't eagerly show completions from the parent path. For example, `asd/foo/../b` will now complete to `asd/foo/../bar` instead of `asd/bar`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-04 03:17:50 +02:00
.join("..")
.join("final_partial")
.join("somefile"),
),
file(
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
dir.join("partial-b")
fix: prevent relative directory traversal from crashing (#12438) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> - fixes #11922 - fixes #12203 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This is a rewrite for some parts of the recursive completion system. The Rust `std::path` structures often ignores things like a trailing `.` because for a complete path, it implies the current directory. We are replacing the use of some of these structs for Strings. A side effect is the slashes being normalized in Windows. For example if we were to type `foo/bar/b`, it would complete it to `foo\bar\baz` because a backward slash is the main separator in windows. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Relative paths are preserved. `..`s in the paths won't eagerly show completions from the parent path. For example, `asd/foo/../b` will now complete to `asd/foo/../bar` instead of `asd/bar`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-04 03:17:50 +02:00
.join("..")
.join("final_partial")
.join("somefile"),
),
file(
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
dir.join("partial-c")
fix: prevent relative directory traversal from crashing (#12438) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> - fixes #11922 - fixes #12203 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This is a rewrite for some parts of the recursive completion system. The Rust `std::path` structures often ignores things like a trailing `.` because for a complete path, it implies the current directory. We are replacing the use of some of these structs for Strings. A side effect is the slashes being normalized in Windows. For example if we were to type `foo/bar/b`, it would complete it to `foo\bar\baz` because a backward slash is the main separator in windows. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Relative paths are preserved. `..`s in the paths won't eagerly show completions from the parent path. For example, `asd/foo/../b` will now complete to `asd/foo/../bar` instead of `asd/bar`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-04 03:17:50 +02:00
.join("..")
.join("final_partial")
.join("somefile"),
),
];
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completion for all files under directories whose names begin with "pa"
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
let file_str = file(dir.join("partial-a").join("have"));
let target_file = format!("rm {file_str}");
let suggestions = completer.complete(&target_file, target_file.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
file(dir.join("partial-a").join("have_ext.exe")),
file(dir.join("partial-a").join("have_ext.txt")),
];
// Match the results
match_suggestions(expected_paths, suggestions);
// Test completion for all files under directories whose names begin with "pa"
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
let file_str = file(dir.join("partial-a").join("have_ext."));
let file_dir = format!("rm {file_str}");
let suggestions = completer.complete(&file_dir, file_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
file(dir.join("partial-a").join("have_ext.exe")),
file(dir.join("partial-a").join("have_ext.txt")),
];
// Match the results
match_suggestions(expected_paths, suggestions);
Fish-like completions for nested directories (#10543) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #5683 you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR allows tab completion for nested directories while only specifying a part of the directory names. To illustrate this, if I type `tar/de/inc` and hit tab, it autocompletes to `./target/debug/incremental`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Nested paths can be tab completed by typing lesser characters. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Tests cases are added. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-02 19:44:51 +02:00
}
#[test]
fn command_ls_with_filecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "ls ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions);
let target_dir = "ls custom_completion.";
let suggestions = completer.complete(target_dir, target_dir.len());
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_open_with_filecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "open ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions);
let target_dir = "open custom_completion.";
let suggestions = completer.complete(target_dir, target_dir.len());
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_rm_with_globcompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "rm ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_cp_with_globcompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "cp ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_save_with_filecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "save ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_touch_with_filecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "touch ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn command_watch_with_filecompletion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "watch ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
#[rstest]
fn subcommand_completions(mut subcommand_completer: NuCompleter) {
let prefix = "foo br";
let suggestions = subcommand_completer.complete(prefix, prefix.len());
match_suggestions(
vec!["foo bar".to_string(), "foo aabrr".to_string()],
suggestions,
);
let prefix = "foo b";
let suggestions = subcommand_completer.complete(prefix, prefix.len());
match_suggestions(
vec![
"foo bar".to_string(),
"foo abaz".to_string(),
"foo aabrr".to_string(),
],
suggestions,
);
}
#[test]
fn file_completion_quoted() {
let (_, _, engine, stack) = new_quote_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "open ";
let suggestions = completer.complete(target_dir, target_dir.len());
let expected_paths: Vec<String> = vec![
"`--help`".to_string(),
"`-42`".to_string(),
"`-inf`".to_string(),
"`4.2`".to_string(),
Force completers to sort in fetch() (#13242) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR fixes the problem pointed out in https://github.com/nushell/nushell/issues/13204, where the Fish-like completions aren't sorted properly (this PR doesn't close that issue because the author there wants more than just fixed sort order). The cause is all of the file/directory completions being fetched first and then sorted all together while being treated as strings. Instead, this PR sorts completions within each individual directory, avoiding treating `/` as part of the path. To do this, I removed the `sort` method from the completer trait (as well as `get_sort_by`) and made all completers sort within the `fetch` method itself. A generic `sort_completions` helper has been added to sort lists of completions, and a more specific `sort_suggestions` helper has been added to sort `Vec<Suggestion>`s. As for the actual change that fixes the sort order for file/directory completions, the `complete_rec` helper now sorts the children of each directory before visiting their children. The file and directory completers don't bother sorting at the end (except to move hidden files down). To reviewers: don't let the 29 changed files scare you, most of those are just the test fixtures :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> This is the current behavior with prefix matching: ![image](https://github.com/nushell/nushell/assets/45539777/6a36e003-8405-45b5-8cbe-d771e0592709) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/f2cbfdb2-b8fd-491b-a378-779147291d2a) Notice how `partial/hello.txt` is the last suggestion, even though it should come before `partial-a`. This is because the ASCII code for `/` is greater than that of `-`, so `partial-` is put before `partial/`. This is this PR's behavior with prefix matching (`partial/hello.txt` is at the start): ![image](https://github.com/nushell/nushell/assets/45539777/3fcea7c9-e017-428f-aa9c-1707e3ab32e0) And with fuzzy matching: ![image](https://github.com/nushell/nushell/assets/45539777/d55635d4-cdb8-440a-84d6-41111499f9f8) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - Modified the partial completions test fixture to test whether this PR even fixed anything - Modified fixture to test sort order of .nu completions (a previous version of my changes didn't sort all the completions at the end but there were no tests catching that) - Added a test for making sure subcommand completions are sorted by Levenshtein distance (a previous version of my changes sorted in alphabetical order but there were no tests catching that) # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-07-03 13:48:06 +02:00
"\'[a] bc.txt\'".to_string(),
"`te st.txt`".to_string(),
"`te#st.txt`".to_string(),
"`te'st.txt`".to_string(),
"`te(st).txt`".to_string(),
fix: complete paths surrounded by quotes or backticks (#10600) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> Fixes #10586 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Any partial path that begins with or is surrounded by a quote or backtick will be tab completed. The completed result would be surrounded by backticks unconditionally. ![output](https://github.com/nushell/nushell/assets/107522312/13e01104-18a1-4483-b010-79985294748b) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> See above. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Formatted and added test cases. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-06 18:45:30 +02:00
format!("`{}`", folder("test dir".into())),
];
match_suggestions(expected_paths, suggestions);
let dir: PathBuf = "test dir".into();
let target_dir = format!("open '{}'", folder(dir.clone()));
let suggestions = completer.complete(&target_dir, target_dir.len());
let expected_paths: Vec<String> = vec![
format!("`{}`", file(dir.join("double quote"))),
format!("`{}`", file(dir.join("single quote"))),
];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn flag_completions() {
// Create a new engine
let (_, _, engine, stack) = new_engine();
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Test completions for the 'ls' flags
let suggestions = completer.complete("ls -", 4);
add `--mime-type(-m)` to `ls` in the `type` column (#7616) # Description This PR adds the `mime-type` to the `type` column if you add the `--mime-type(-m)` flag to `ls`. <img width="853" alt="Screenshot 2022-12-27 at 11 43 20 AM" src="https://user-images.githubusercontent.com/343840/209705499-27fe40fe-0356-4d9d-97f2-4b2dc52e0963.png"> <img width="781" alt="Screenshot 2022-12-27 at 11 45 53 AM" src="https://user-images.githubusercontent.com/343840/209705509-4d677389-fd68-401e-a7af-3fc6052743b6.png"> # User-Facing Changes If you specify the `-m` flag, you get the "guessed at" mime type. The guess is based on the file name and uses this crate https://docs.rs/mime_guess/latest/mime_guess/ for the guessing. Part of issue #7612 and and #7524 There's some debate on if the `mime-type` should be added to the `type` column or if there should be a separate `mime` column. I tend to lean on the side of `type` since it's technically a type and it's only in that column if you ask it to be there. Also, I'd prefer to reuse a column rather than having a list of sprawling columns. Also, as @KodiCraft suggested, there is precedence as with `ls -d` where the summed size is in the size column. I could go either way and if someone wants to create a `mime` column, we'd probably accept it. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-27 19:46:23 +01:00
assert_eq!(16, suggestions.len());
let expected: Vec<String> = vec![
"--all".into(),
"--directory".into(),
"--du".into(),
"--full-paths".into(),
"--help".into(),
"--long".into(),
add `--mime-type(-m)` to `ls` in the `type` column (#7616) # Description This PR adds the `mime-type` to the `type` column if you add the `--mime-type(-m)` flag to `ls`. <img width="853" alt="Screenshot 2022-12-27 at 11 43 20 AM" src="https://user-images.githubusercontent.com/343840/209705499-27fe40fe-0356-4d9d-97f2-4b2dc52e0963.png"> <img width="781" alt="Screenshot 2022-12-27 at 11 45 53 AM" src="https://user-images.githubusercontent.com/343840/209705509-4d677389-fd68-401e-a7af-3fc6052743b6.png"> # User-Facing Changes If you specify the `-m` flag, you get the "guessed at" mime type. The guess is based on the file name and uses this crate https://docs.rs/mime_guess/latest/mime_guess/ for the guessing. Part of issue #7612 and and #7524 There's some debate on if the `mime-type` should be added to the `type` column or if there should be a separate `mime` column. I tend to lean on the side of `type` since it's technically a type and it's only in that column if you ask it to be there. Also, I'd prefer to reuse a column rather than having a list of sprawling columns. Also, as @KodiCraft suggested, there is precedence as with `ls -d` where the summed size is in the size column. I could go either way and if someone wants to create a `mime` column, we'd probably accept it. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-27 19:46:23 +01:00
"--mime-type".into(),
"--short-names".into(),
"-D".into(),
"-a".into(),
"-d".into(),
"-f".into(),
"-h".into(),
"-l".into(),
add `--mime-type(-m)` to `ls` in the `type` column (#7616) # Description This PR adds the `mime-type` to the `type` column if you add the `--mime-type(-m)` flag to `ls`. <img width="853" alt="Screenshot 2022-12-27 at 11 43 20 AM" src="https://user-images.githubusercontent.com/343840/209705499-27fe40fe-0356-4d9d-97f2-4b2dc52e0963.png"> <img width="781" alt="Screenshot 2022-12-27 at 11 45 53 AM" src="https://user-images.githubusercontent.com/343840/209705509-4d677389-fd68-401e-a7af-3fc6052743b6.png"> # User-Facing Changes If you specify the `-m` flag, you get the "guessed at" mime type. The guess is based on the file name and uses this crate https://docs.rs/mime_guess/latest/mime_guess/ for the guessing. Part of issue #7612 and and #7524 There's some debate on if the `mime-type` should be added to the `type` column or if there should be a separate `mime` column. I tend to lean on the side of `type` since it's technically a type and it's only in that column if you ask it to be there. Also, I'd prefer to reuse a column rather than having a list of sprawling columns. Also, as @KodiCraft suggested, there is precedence as with `ls -d` where the summed size is in the size column. I could go either way and if someone wants to create a `mime` column, we'd probably accept it. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-27 19:46:23 +01:00
"-m".into(),
"-s".into(),
];
// Match results
match_suggestions(expected, suggestions);
}
#[test]
fn folder_with_directorycompletions() {
// Create a new engine
let (dir, dir_str, engine, stack) = new_engine();
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Test completions for the current folder
Migrate to a new PWD API (#12603) This is the first PR towards migrating to a new `$env.PWD` API that returns potentially un-canonicalized paths. Refer to PR #12515 for motivations. ## New API: `EngineState::cwd()` The goal of the new API is to cover both parse-time and runtime use case, and avoid unintentional misuse. It takes an `Option<Stack>` as argument, which if supplied, will search for `$env.PWD` on the stack in additional to the engine state. I think with this design, there's less confusion over parse-time and runtime environments. If you have access to a stack, just supply it; otherwise supply `None`. ## Deprecation of other PWD-related APIs Other APIs are re-implemented using `EngineState::cwd()` and properly documented. They're marked deprecated, but their behavior is unchanged. Unused APIs are deleted, and code that accesses `$env.PWD` directly without using an API is rewritten. Deprecated APIs: * `EngineState::current_work_dir()` * `StateWorkingSet::get_cwd()` * `env::current_dir()` * `env::current_dir_str()` * `env::current_dir_const()` * `env::current_dir_str_const()` Other changes: * `EngineState::get_cwd()` (deleted) * `StateWorkingSet::list_env()` (deleted) * `repl::do_run_cmd()` (rewritten with `env::current_dir_str()`) ## `cd` and `pwd` now use logical paths by default This pulls the changes from PR #12515. It's currently somewhat broken because using non-canonicalized paths exposed a bug in our path normalization logic (Issue #12602). Once that is fixed, this should work. ## Future plans This PR needs some tests. Which test helpers should I use, and where should I put those tests? I noticed that unquoted paths are expanded within `eval_filepath()` and `eval_directory()` before they even reach the `cd` command. This means every paths is expanded twice. Is this intended? Once this PR lands, the plan is to review all usages of the deprecated APIs and migrate them to `EngineState::cwd()`. In the meantime, these usages are annotated with `#[allow(deprecated)]` to avoid breaking CI. --------- Co-authored-by: Jakub Žádník <kubouch@gmail.com>
2024-05-03 13:33:09 +02:00
let target_dir = format!("cd {dir_str}{MAIN_SEPARATOR}");
let suggestions = completer.complete(&target_dir, target_dir.len());
// Create the expected values
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
folder(dir.join("another")),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
folder(dir.join("directory_completion")),
folder(dir.join("test_a")),
folder(dir.join("test_b")),
folder(dir.join(".hidden_folder")),
];
// Match the results
match_suggestions(expected_paths, suggestions);
}
#[test]
fn variables_completions() {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = "let actor = { name: 'Tom Hardy', age: 44 }";
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Test completions for $nu
let suggestions = completer.complete("$nu.", 4);
add a system level folder for future autoloading (#13180) # Description This PR adds a directory to the `$nu` constant that shows where the system level autoload directory is located at. This folder is modifiable at compile time with environment variables. ```rust // Create a system level directory for nushell scripts, modules, completions, etc // that can be changed by setting the NU_VENDOR_AUTOLOAD_DIR env var on any platform // before nushell is compiled OR if NU_VENDOR_AUTOLOAD_DIR is not set for non-windows // systems, the PREFIX env var can be set before compile and used as PREFIX/nushell/vendor/autoload // pseudo code // if env var NU_VENDOR_AUTOLOAD_DIR is set, in any platform, use it // if not, if windows, use ALLUSERPROFILE\nushell\vendor\autoload // if not, if non-windows, if env var PREFIX is set, use PREFIX/share/nushell/vendor/autoload // if not, use the default /usr/share/nushell/vendor/autoload ``` ### Windows default ```nushell ❯ $nu.vendor-autoload-dir C:\ProgramData\nushell\vendor\autoload ``` ### Non-Windows default ```nushell ❯ $nu.vendor-autoload-dir /usr/local/share/nushell/vendor/autoload ``` ### Non-Windows with PREFIX set ```nushell ❯ PREFIX=/usr/bob cargo r ❯ $nu.vendor-autoload-dir /usr/bob/share/nushell/vendor/autoload ``` ### Non-Windows with NU_VENDOR_AUTOLOAD_DIR set ```nushell ❯ NU_VENDOR_AUTOLOAD_DIR=/some/other/path/nushell/stuff cargo r ❯ $nu.vendor-autoload-dir /some/other/path/nushell/stuff ``` > [!IMPORTANT] To be clear, this PR does not do the auto-loading, it just sets up the folder to support that functionality that can be added in a later PR. The PR also does not create the folder defined. It's just setting the $nu constant.   # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-06-20 13:30:43 +02:00
assert_eq!(18, suggestions.len());
let expected: Vec<String> = vec![
add `$nu.data-dir` for completions and `$nu.cache-dir` for other uses (#13122) # Description This PR is an attempt to add a standard location for people to put completions in. I saw this topic come up again recently and IIRC we decided to create a standard location. I used the dirs-next crate to dictate where these locations are. I know some people won't like that but at least this gets the ball rolling in a direction that has a standard directory. This is what the default NU_LIB_DIRS looks like now in the default_env.nu. It should also be like this when starting nushell with `nu -n` ```nushell $env.NU_LIB_DIRS = [ ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts ($nu.data-dir | path join 'completions') # default home for nushell completions ] ``` I also added these default folders to the `$nu` variable so now there is `$nu.data-path` and `$nu.cache-path`. ## Data Dir Default ![image](https://github.com/nushell/nushell/assets/343840/aeeb7cd6-17b4-43e8-bb6f-986a0c7fce23) While I was in there, I also decided to add a cache dir ## Cache Dir Default ![image](https://github.com/nushell/nushell/assets/343840/87dead66-4911-4f67-bfb2-acb16f386674) ### This is what the default looks like in Ubuntu. ![image](https://github.com/nushell/nushell/assets/343840/bca8eae8-8c18-47e8-b64f-3efe34f0004f) ### This is what it looks like with XDG_CACHE_HOME and XDG_DATA_HOME overridden ```nushell XDG_DATA_HOME=/tmp/data_home XDG_CACHE_HOME=/tmp/cache_home cargo r ``` ![image](https://github.com/nushell/nushell/assets/343840/fae86d50-9821-41f1-868e-3814eca3730b) ### This is what the defaults look like in Windows (username scrubbed to protect the innocent) ![image](https://github.com/nushell/nushell/assets/343840/3ebdb5cd-0150-448c-aff5-c57053e4788a) How my NU_LIB_DIRS is set in the images above ```nushell $env.NU_LIB_DIRS = [ ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts '/Users/fdncred/src/nu_scripts' ($nu.config-path | path dirname) ($nu.data-dir | path join 'completions') # default home for nushell completions ] ``` Let the debate begin. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-06-11 21:10:31 +02:00
"cache-dir".into(),
"config-path".into(),
"current-exe".into(),
add `$nu.data-dir` for completions and `$nu.cache-dir` for other uses (#13122) # Description This PR is an attempt to add a standard location for people to put completions in. I saw this topic come up again recently and IIRC we decided to create a standard location. I used the dirs-next crate to dictate where these locations are. I know some people won't like that but at least this gets the ball rolling in a direction that has a standard directory. This is what the default NU_LIB_DIRS looks like now in the default_env.nu. It should also be like this when starting nushell with `nu -n` ```nushell $env.NU_LIB_DIRS = [ ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts ($nu.data-dir | path join 'completions') # default home for nushell completions ] ``` I also added these default folders to the `$nu` variable so now there is `$nu.data-path` and `$nu.cache-path`. ## Data Dir Default ![image](https://github.com/nushell/nushell/assets/343840/aeeb7cd6-17b4-43e8-bb6f-986a0c7fce23) While I was in there, I also decided to add a cache dir ## Cache Dir Default ![image](https://github.com/nushell/nushell/assets/343840/87dead66-4911-4f67-bfb2-acb16f386674) ### This is what the default looks like in Ubuntu. ![image](https://github.com/nushell/nushell/assets/343840/bca8eae8-8c18-47e8-b64f-3efe34f0004f) ### This is what it looks like with XDG_CACHE_HOME and XDG_DATA_HOME overridden ```nushell XDG_DATA_HOME=/tmp/data_home XDG_CACHE_HOME=/tmp/cache_home cargo r ``` ![image](https://github.com/nushell/nushell/assets/343840/fae86d50-9821-41f1-868e-3814eca3730b) ### This is what the defaults look like in Windows (username scrubbed to protect the innocent) ![image](https://github.com/nushell/nushell/assets/343840/3ebdb5cd-0150-448c-aff5-c57053e4788a) How my NU_LIB_DIRS is set in the images above ```nushell $env.NU_LIB_DIRS = [ ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts '/Users/fdncred/src/nu_scripts' ($nu.config-path | path dirname) ($nu.data-dir | path join 'completions') # default home for nushell completions ] ``` Let the debate begin. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-06-11 21:10:31 +02:00
"data-dir".into(),
"default-config-dir".into(),
"env-path".into(),
"history-enabled".into(),
"history-path".into(),
"home-path".into(),
"is-interactive".into(),
"is-login".into(),
"loginshell-path".into(),
"os-info".into(),
"pid".into(),
"plugin-path".into(),
FEATURE: add the startup time to `$nu` (#8353) # Description in https://github.com/nushell/nushell/issues/8311 and the discord server, the idea of moving the default banner from the `rust` source to the `nushell` standar library has emerged :yum: however, in order to do this, one need to have access to all the variables used in the default banner => all of them are accessible because known constants, except for the startup time of the shell, which is not anywhere in the shell... #### this PR adds exactly this, i.e. the new `startup_time` to the `$nu` variable, which is computed to have the exact same value as the value shown in the banner. ## the changes in order to achieve this, i had to - add `startup_time` as an `i64` to the `EngineState` => this is, to the best of my knowledge, the easiest way to pass such an information around down to where the banner startup time is computed and where the `$nu` variable is evaluated - add `startup-time` to the `$nu` variable and use the `EngineState` getter for `startup_time` to show it as a `Value::Duration` - pass `engine_state` as a `&mut`able argument from `main.rs` down to `repl.rs` to allow the setter to change the value of `startup_time` => without this, the value would not change and would show `-1ns` as the default value... - the value of the startup time is computed in `evaluate_repl` in `repl.rs`, only once at the beginning, and the same value is used in the default banner :ok_hand: # User-Facing Changes one can now access to the same time as shown in the default banner with ```bash $nu.startup-time ``` # Tests + Formatting - :green_circle: `cargo fmt --all` - :green_circle: `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` - :green_circle: `cargo test --workspace` # After Submitting ``` $nothing ```
2023-03-09 21:18:58 +01:00
"startup-time".into(),
"temp-path".into(),
add a system level folder for future autoloading (#13180) # Description This PR adds a directory to the `$nu` constant that shows where the system level autoload directory is located at. This folder is modifiable at compile time with environment variables. ```rust // Create a system level directory for nushell scripts, modules, completions, etc // that can be changed by setting the NU_VENDOR_AUTOLOAD_DIR env var on any platform // before nushell is compiled OR if NU_VENDOR_AUTOLOAD_DIR is not set for non-windows // systems, the PREFIX env var can be set before compile and used as PREFIX/nushell/vendor/autoload // pseudo code // if env var NU_VENDOR_AUTOLOAD_DIR is set, in any platform, use it // if not, if windows, use ALLUSERPROFILE\nushell\vendor\autoload // if not, if non-windows, if env var PREFIX is set, use PREFIX/share/nushell/vendor/autoload // if not, use the default /usr/share/nushell/vendor/autoload ``` ### Windows default ```nushell ❯ $nu.vendor-autoload-dir C:\ProgramData\nushell\vendor\autoload ``` ### Non-Windows default ```nushell ❯ $nu.vendor-autoload-dir /usr/local/share/nushell/vendor/autoload ``` ### Non-Windows with PREFIX set ```nushell ❯ PREFIX=/usr/bob cargo r ❯ $nu.vendor-autoload-dir /usr/bob/share/nushell/vendor/autoload ``` ### Non-Windows with NU_VENDOR_AUTOLOAD_DIR set ```nushell ❯ NU_VENDOR_AUTOLOAD_DIR=/some/other/path/nushell/stuff cargo r ❯ $nu.vendor-autoload-dir /some/other/path/nushell/stuff ``` > [!IMPORTANT] To be clear, this PR does not do the auto-loading, it just sets up the folder to support that functionality that can be added in a later PR. The PR also does not create the folder defined. It's just setting the $nu constant.   # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-06-20 13:30:43 +02:00
"vendor-autoload-dir".into(),
];
// Match results
match_suggestions(expected, suggestions);
// Test completions for $nu.h (filter)
let suggestions = completer.complete("$nu.h", 5);
assert_eq!(3, suggestions.len());
let expected: Vec<String> = vec![
"history-enabled".into(),
"history-path".into(),
"home-path".into(),
];
// Match results
match_suggestions(expected, suggestions);
// Test completions for $nu.os-info
let suggestions = completer.complete("$nu.os-info.", 12);
assert_eq!(4, suggestions.len());
let expected: Vec<String> = vec![
"arch".into(),
"family".into(),
"kernel_version".into(),
"name".into(),
];
// Match results
match_suggestions(expected, suggestions);
// Test completions for custom var
let suggestions = completer.complete("$actor.", 7);
assert_eq!(2, suggestions.len());
let expected: Vec<String> = vec!["age".into(), "name".into()];
// Match results
match_suggestions(expected, suggestions);
// Test completions for custom var (filtering)
let suggestions = completer.complete("$actor.n", 8);
assert_eq!(1, suggestions.len());
let expected: Vec<String> = vec!["name".into()];
// Match results
match_suggestions(expected, suggestions);
// Test completions for $env
let suggestions = completer.complete("$env.", 5);
assert_eq!(3, suggestions.len());
#[cfg(windows)]
let expected: Vec<String> = vec!["PWD".into(), "Path".into(), "TEST".into()];
#[cfg(not(windows))]
let expected: Vec<String> = vec!["PATH".into(), "PWD".into(), "TEST".into()];
// Match results
match_suggestions(expected, suggestions);
// Test completions for $env
let suggestions = completer.complete("$env.T", 6);
assert_eq!(1, suggestions.len());
let expected: Vec<String> = vec!["TEST".into()];
// Match results
match_suggestions(expected, suggestions);
}
#[test]
fn alias_of_command_and_flags() {
let (dir, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -l"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let suggestions = completer.complete("ll t", 4);
#[cfg(windows)]
let expected_paths: Vec<String> = vec!["test_a\\".to_string(), "test_b\\".to_string()];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn alias_of_basic_command() {
let (dir, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls "#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let suggestions = completer.complete("ll t", 4);
#[cfg(windows)]
let expected_paths: Vec<String> = vec!["test_a\\".to_string(), "test_b\\".to_string()];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
match_suggestions(expected_paths, suggestions)
}
#[test]
fn alias_of_another_alias() {
let (dir, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -la"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir.clone()).is_ok());
// Create the second alias
let alias = r#"alias lf = ll -f"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let suggestions = completer.complete("lf t", 4);
#[cfg(windows)]
let expected_paths: Vec<String> = vec!["test_a\\".to_string(), "test_b\\".to_string()];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
match_suggestions(expected_paths, suggestions)
}
fn run_external_completion(completer: &str, input: &str) -> Vec<Suggestion> {
let completer = format!("$env.config.completions.external.completer = {completer}");
// Create a new engine
let (dir, _, mut engine_state, mut stack) = new_engine();
let (block, delta) = {
let mut working_set = StateWorkingSet::new(&engine_state);
let block = parse(&mut working_set, None, completer.as_bytes(), false);
assert!(working_set.parse_errors.is_empty());
(block, working_set.render())
};
assert!(engine_state.merge_delta(delta).is_ok());
assert!(
eval_block::<WithoutDebug>(&engine_state, &mut stack, &block, PipelineData::Empty).is_ok()
);
// Merge environment into the permanent state
assert!(engine_state.merge_env(&mut stack, &dir).is_ok());
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine_state), Arc::new(stack));
completer.complete(input, input.len())
}
#[test]
fn unknown_command_completion() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let target_dir = "thiscommanddoesnotexist ";
let suggestions = completer.complete(target_dir, target_dir.len());
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions)
}
#[rstest]
fn flagcompletion_triggers_after_cursor(mut completer: NuCompleter) {
let suggestions = completer.complete("tst -h", 5);
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn customcompletion_triggers_after_cursor(mut completer_strings: NuCompleter) {
let suggestions = completer_strings.complete("my-command c", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn customcompletion_triggers_after_cursor_piped(mut completer_strings: NuCompleter) {
let suggestions = completer_strings.complete("my-command c | ls", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn flagcompletion_triggers_after_cursor_piped(mut completer: NuCompleter) {
let suggestions = completer.complete("tst -h | ls", 5);
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
match_suggestions(expected, suggestions);
}
#[test]
fn filecompletions_triggers_after_cursor() {
let (_, _, engine, stack) = new_engine();
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
let suggestions = completer.complete("cp test_c", 3);
#[cfg(windows)]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another\\".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion\\".to_string(),
"nushell".to_string(),
"test_a\\".to_string(),
"test_b\\".to_string(),
".hidden_file".to_string(),
".hidden_folder\\".to_string(),
];
#[cfg(not(windows))]
let expected_paths: Vec<String> = vec![
files and directory completions now use ascending ordering rather than Levenshtein. #8023 (#8085) # Description This change sorts completions for files and directories by the ascending ordering method, related to issue: [#8023](https://github.com/nushell/nushell/issues/8023) Currently the Suggestions are being sorted twice, so it's now following the convention from `completion/base.rs` to match on the `self.get_sort_by()` result. # User-Facing Changes Previously the suggestions were being sorted by the Levenshtein method: ``` /home/rdevenney/projects/open_source/nushell| cd src/ wix/ docs/ tests/ assets/ crates/ docker/ images/ target/ benches/ pkg_mgrs/ .git/ .cargo/ .github/ ``` Now when you tab for autocompletions, they show up in ascending alphabetical order as shown below (with hidden files/folders at the end). ``` /home/rdevenney/projects/open_source/nushell| cd assets/ benches/ crates/ docker/ docs/ images/ pkg_mgrs/ src/ target/ tests/ wix/ .cargo/ .git/ .github/ ``` And when you've already typed a bit of the path: ``` /home/rdevenney/projects/open_source/nushell| cd crates/nu crates/nu-cli/ crates/nu-color-config/ crates/nu-command/ crates/nu-engine/ crates/nu-explore/ crates/nu-glob/ crates/nu-json/ crates/nu-parser/ crates/nu-path/ crates/nu-plugin/ crates/nu-pretty-hex/ crates/nu-protocol/ crates/nu-system/ crates/nu-table/ crates/nu-term-grid/ crates/nu-test-support/ crates/nu-utils/ crates/nu_plugin_custom_values/ crates/nu_plugin_example/ crates/nu_plugin_formats/ crates/nu_plugin_gstat/ crates/nu_plugin_inc/ crates/nu_plugin_python/ crates/nu_plugin_query/ ``` And another for when there are files and directories present: ``` /home/rdevenney/projects/open_source/nushell/crates/nu-cli/src| nvim 02/16/2023 08:22:16 AM commands.rs completions/ config_files.rs eval_file.rs lib.rs menus/ nu_highlight.rs print.rs prompt.rs prompt_update.rs reedline_config.rs repl.rs syntax_highlight.rs util.rs validation.rs ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: [*] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) [*] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style [*] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 14:03:48 +01:00
"another/".to_string(),
"custom_completion.nu".to_string(),
improve completions of `use` and `overlay use` (#11330) # Description this PR is two-fold - make `use` and `overlay use` use the same completion algorithm in 48f29b633 - list directory modules in completions of both with 402acde5c # User-Facing Changes i currently have the following in my `NU_LIB_DIRS` <details> <summary>click to see the script</summary> ```nushell for dir in $env.NU_LIB_DIRS { print $dir print (ls $dir --short-names | select name type) } ``` </details> ``` /home/amtoine/.local/share/nupm/modules #┬────────name────────┬type 0│nu-git-manager │dir 1│nu-git-manager-sugar│dir 2│nu-hooks │dir 3│nu-scripts │dir 4│nu-themes │dir 5│nupm │dir ─┴────────────────────┴──── /home/amtoine/.config/nushell/overlays #┬──name──┬type 0│ocaml.nu│file ─┴────────┴──── ``` > **Note** > all the samples below are run from the Nushell repo, i.e. a directory with a `toolkit.nu` module ## before the changes - `use` would give me `["ocaml.nu", "toolkit.nu"]` - `overlay use` would give me `[]` ## after the changes both commands give me ```nushell [ "nupm/", "ocaml.nu", "toolkit.nu", "nu-scripts/", "nu-git-manager/", "nu-git-manager-sugar/", ] ``` # Tests + Formatting - adds a new `directory_completion/mod.nu` to the completion fixtures - make sure `source-env`, `use` and `overlay-use` are all tested in the _dotnu_ test - fix all the other tests that use completions in the fixtures directory for completions # After Submitting
2023-12-19 10:14:34 +01:00
"directory_completion/".to_string(),
"nushell".to_string(),
"test_a/".to_string(),
"test_b/".to_string(),
".hidden_file".to_string(),
".hidden_folder/".to_string(),
];
match_suggestions(expected_paths, suggestions);
}
#[rstest]
fn extern_custom_completion_positional(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam ", 5);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn extern_custom_completion_long_flag_1(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam --foo=", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn extern_custom_completion_long_flag_2(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam --foo ", 11);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn extern_custom_completion_long_flag_short(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam -f ", 8);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn extern_custom_completion_short_flag(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam -b ", 8);
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn extern_complete_flags(mut extern_completer: NuCompleter) {
let suggestions = extern_completer.complete("spam -", 6);
let expected: Vec<String> = vec!["--foo".into(), "-b".into(), "-f".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
let suggestions = custom_completer.complete("cmd foo bar", 8);
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {
let suggestions = custom_completer.complete("cmd foo bar", 8);
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn custom_completer_triggers_cursor_next_to_word(mut custom_completer: NuCompleter) {
let suggestions = custom_completer.complete("cmd foo bar", 11);
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into()];
match_suggestions(expected, suggestions);
}
#[rstest]
fn custom_completer_triggers_cursor_after_word(mut custom_completer: NuCompleter) {
let suggestions = custom_completer.complete("cmd foo bar ", 12);
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into(), "".into()];
match_suggestions(expected, suggestions);
}
#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7648() {
let (dir, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ea = ^$env.EDITOR /tmp/test.s"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Issue #7648
// Nushell crashes when an alias name is shorter than the alias command
// and the alias command is a external command
// This happens because of offset is not correct.
// This crashes before PR #7779
let _suggestions = completer.complete("e", 1);
}
#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7754() {
let (dir, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -l"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
// Issue #7754
// Nushell crashes when an alias name is shorter than the alias command
// and the alias command contains pipes.
// This crashes before PR #7756
let _suggestions = completer.complete("ll -a | c", 9);
}
#[test]
fn get_path_env_var_8003() {
// Create a new engine
let (_, _, engine, _) = new_engine();
// Get the path env var in a platform agnostic way
let the_path = engine.get_path_env_var();
// Make sure it's not empty
assert!(the_path.is_some());
}