Skip to content

Fish-like completions for nested directories#10543

Merged
sophiajt merged 19 commits intonushell:mainfrom
lavafroth:smart-path-completions
Oct 2, 2023
Merged

Fish-like completions for nested directories#10543
sophiajt merged 19 commits intonushell:mainfrom
lavafroth:smart-path-completions

Conversation

@lavafroth
Copy link
Copy Markdown
Contributor

@lavafroth lavafroth commented Sep 29, 2023

Description

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

Nested paths can be tab completed by typing lesser characters.

Tests + Formatting

Tests cases are added.

After Submitting

@lavafroth
Copy link
Copy Markdown
Contributor Author

Screencast.from.2023-09-29.13-07-41.webm

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 29, 2023

This looks cool! Thanks! There is something similar to this with cd if enabled, but it does not support completions. But you can do cd a/b/c and it works.

@lavafroth
Copy link
Copy Markdown
Contributor Author

Update: I changed the functions a lot, making sure to conform to the engine_state for each completer (which I previously ignored). Also, I remove the prefix with the pathdiff crate to make relative paths like ../some/thi/n/g stay relative. I would love to hear everyone's feedback on this. Thanks!

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 29, 2023

Have you tested it on Windows? I'm hoping it works there too.

@lavafroth
Copy link
Copy Markdown
Contributor Author

lavafroth commented Sep 29, 2023 via email

@sophiajt
Copy link
Copy Markdown
Contributor

While you're testing, another thing to check for is if it works with filepaths that have spaces in them.

@lavafroth
Copy link
Copy Markdown
Contributor Author

lavafroth commented Sep 29, 2023 via email

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 29, 2023

I just tested on Windows and it works as long as the slashes point left like regular windows slashes. Maybe it's just me, that's great, but I tend to cd /a/b/c/d even on Windows.

Complete paths from root c:\ or \

I'm not sure if it doesn't work with spaces in file names or if it just doesn't like what I'm doing.

cd \pro\a\a<tab>
cd c:\pro\a\a<tab>

both go to the same folder c:\program files\adobe\adobe acrobat reader dc

Complete c:\temp as c:\t

here's another weird one

cd \t<tab>

completes to cd src\tests\

cd c:\t<tab>`

returns no records found

In the root C:\

cd pro\a\a<tab>

no records found

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 29, 2023

One more test. Just a regular folder with a space in it with a folder in it seems to work on windows.
image

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 29, 2023

I'm retesting because on some system I use carapace. So just to be verbose, this is on my Lenovo on Win11 launched with cargo r -- -n --no-std-lib

  1. cd cr\nu-c\s\b<tab> - Works! expands to crates\nu-command\src\bytes\
  2. cr\nu-c\s\b<tab> - Works! expands to crates\nu-command\src\bytes\
  3. cd pro\a\a<tab> - Works!
    image
  4. pro\a\a<tab> - Works! same image as above
  5. cd t\set<tab> - works!
    image
  6. cd \t\set<tab> - does not work
    image
  7. cd c:\t\set<tab> - does not work
  8. cd c:/t/set<tab> - does not work

So, what I see right now on Windows 11 is drive names don't work like C: or D: or referring to the root of a drive as \ doesn't work.

@lavafroth
Copy link
Copy Markdown
Contributor Author

lavafroth commented Sep 30, 2023 via email

@lavafroth
Copy link
Copy Markdown
Contributor Author

I added support for drive letters like c: with an optional slash like c:/ or c:\. I also added support for / as the system root. However, since we have been using platform specific slashes everywhere else, /wind/sys won't autocomplete but /w\sys will. We can change this behavior if wanted.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 30, 2023

My preference would be for all these to "just work"

  • c:/blah/<tab>
  • c:\blah\<tab>
  • c:\blah/<tab>
  • \w\sys<tab>
  • /w/sys<tab>
  • /w\sys<tab>
  • \w/sys<tab>

Basically, any slash direction with tab should work. I'm also fine with homogenizing the slashes so if you were to do something weird like \a/b\c/d\e/f<tab> it would do \a\b\c\d\e\f or /a/b/c/d/e/f.

I'm interested to see what others think.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 30, 2023

BTW, just let me say that is an epic PR. One of the biggest complaints we have is about completions not working the way people expect them to. This PR won't fix 100% of people's complaints, but man, it goes a long way to making our path completions better. Thanks so much for investing your time into nushell. ❤️

@sophiajt
Copy link
Copy Markdown
Contributor

I think we should support the slash direction that's native for that platform for the first version of this change. If people want to it to be more flexible than that, we can improve it further later.

Technically the other slash direction is valid as a filename, for example I can do touch \ on my mac and get a file, so being conservative at first is probably a better place to start from.

@lavafroth
Copy link
Copy Markdown
Contributor Author

Alright, I have implemented the slash homogenization. I also made sure to keep ~ and .. relative. I've tried to make the code concise albeit there's still quite some room for improvement. Tell me what you folks think!

@lavafroth
Copy link
Copy Markdown
Contributor Author

Bare string manipulations have been tedious, so I rewrote quite a bit of the code to use std::path::Components. The code has much less overhead now, I don't have to perform error prone checks for .., ~ or a drive letter from the partial string itself. The slashes also get homogenized as a by-product of using components. Finally, the binary size is way smaller that previous iterations of the PR.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 2, 2023

I'm happy to see the CI green. I fought with it yesterday because macos kept puking.

I'm wondering if there's a way to add tests? If this works the way we want it to, we'd like to preserve that functionality and protect it from inadvertent changes breaking it. One way to do that is with some tests.

@lavafroth
Copy link
Copy Markdown
Contributor Author

lavafroth commented Oct 2, 2023 via email

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 2, 2023

I've tested it. I love it. ❤️ Everything that failed before on Windows is working great now!

Typo checker thinks the partial "som" for the filename "somefile" is a typo. Checks out.
@lavafroth
Copy link
Copy Markdown
Contributor Author

Whoops, typo checker thinks a file's prefix is a typo. I'll fix it.

@lavafroth
Copy link
Copy Markdown
Contributor Author

Let me know if there's anything else I have to do before this gets merged!

Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it and I'm ready to land it. Let's see if there are differing opinions.

@sophiajt
Copy link
Copy Markdown
Contributor

sophiajt commented Oct 2, 2023

+1 from me too. Let's do it.

@sophiajt sophiajt merged commit 5c15a4d into nushell:main Oct 2, 2023
@fdncred fdncred added the notes:mention Include the release notes summary in the "Hall of Fame" section label Oct 2, 2023
sophiajt added a commit that referenced this pull request Oct 2, 2023
# Description

This removes the old style "cd with abbreviations" that would attempt to
guess what directory you wanted to `cd` to. This would sometimes have
false positives, so we left it off by default in the config.

In the current main, we have much-improved path completions
(#10543) so you can now do `cd
a/b<tab>` and get a much better experience (because you can see the
directory you're about to cd to). This removes the need for the previous
abbreviation system.

# User-Facing Changes

This does remove the old abbreviation system. It will likely mean that
old config files that have settings for abbreviations will now get
errors.

update: here's an example of the error you'll see:


![image](https://github.com/nushell/nushell/assets/547158/6847a25d-895a-4b92-8251-278a57e8d29a)

# 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.
-->
@lavafroth lavafroth deleted the smart-path-completions branch October 4, 2023 02:26
@AucaCoyan
Copy link
Copy Markdown
Contributor

I saw this new feature in the last 0.86 release, I've been looking forward for this in a long time! Thanks @lavafroth ❤️

justinbarclay added a commit to justinbarclay/dotfiles that referenced this pull request Oct 31, 2023
it is now deprecated due to nushell/nushell#10543
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
<!--
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 nushell#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.
-->
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description

This removes the old style "cd with abbreviations" that would attempt to
guess what directory you wanted to `cd` to. This would sometimes have
false positives, so we left it off by default in the config.

In the current main, we have much-improved path completions
(nushell#10543) so you can now do `cd
a/b<tab>` and get a much better experience (because you can see the
directory you're about to cd to). This removes the need for the previous
abbreviation system.

# User-Facing Changes

This does remove the old abbreviation system. It will likely mean that
old config files that have settings for abbreviations will now get
errors.

update: here's an example of the error you'll see:


![image](https://github.com/nushell/nushell/assets/547158/6847a25d-895a-4b92-8251-278a57e8d29a)

# 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.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:mention Include the release notes summary in the "Hall of Fame" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants