mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
b7af715f6b
3 Commits
Author | SHA1 | Message | Date | |
---|---|---|---|---|
Yash Thakur
|
9e738193f3
|
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. --> |
||
Wind
|
58cf0c56f8
|
add some completion tests (#12908)
# Description ```nushell ❯ ls ╭───┬───────┬──────┬──────┬──────────╮ │ # │ name │ type │ size │ modified │ ├───┼───────┼──────┼──────┼──────────┤ │ 0 │ a.txt │ file │ 0 B │ now │ ╰───┴───────┴──────┴──────┴──────────╯ ❯ ls a. NO RECORDS FOUND ``` There is a completion issue on previous version, I think @amtoine have reproduced it before. But currently I can't reproduce it on latest main. To avoid such regression, I added some tests for completion. --------- Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com> |
||
Himadri Bhattacharjee
|
5c15a4dd6e
|
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. --> |