warpdotdev / Warp

Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.
https://warp.dev
Other
20.93k stars 358 forks source link

Autocompletion - Generally parse filepaths correctly (throughout the command entry experience) #24

Open donaldguy opened 3 years ago

donaldguy commented 3 years ago

(Partially) Extracted from (previous draft) of https://github.com/warpdotdev/warp/issues/16#issuecomment-882120458 :

Currently the tab completion algorithm takes a fairly conservative approach to offering completions for file names. While some commands' (cd, ls, file, stat, somewhat surprisingly tar, … ) completions are configured to assume a file may come at an initial (or any post-flag) position and offer suggestions accordingly, others (mkdir, vi - at least with my shell config, …) play it safe and wait to see an explicit -- before any file completions are offered.

This is the case even when Tab is proceeded by ./, ../ or /

I suggest there are at least 3 heuristic approaches that might be reasonable:

Assuming paths should follow on:

  1. ^\.{0,2}/ or indeed ^[./] – this would catch all explicitly rooted paths (at the cost of ignoring or requiring special handling for the rarely-used DOS-style /? flag; and having some false positives)
  2. ^[^-+] except where there is an explicit expectation of sub-commands for e.g. git, or stuff like dd's k=v style, etc. This is likely how many commands currently behave
  3. the latter but as part of a state machine that gets more eager when/if someone typed (or accepted suggestion(s) for) {-, -- or +} style flag(s) followed by a space and not then another - or +

The logic of 3 would aim so that:

*That accepting doesn't add a trailing space is perhaps a bug as it stands, because additional Tab seems to be ignored rather than offering additional flags to add to an ~option clump (as does, for example, /usr/share/zsh/5.8/functions/_ls /usr/share/zsh/5.8/functions/_mkdir ). As such one is gonna have to type Space-Tab even if one does want more flag suggestions (unless there is some way to multi-select?)

If it were the default behavior, however, one would likely still want to suppress for Java/Go-std-lib -key=val and POSIX(?) --key=val style flags

elviskahoro commented 2 years ago

If I type

ls -l path/subfolder/filen

Then hit tab, it will work fine.

vspipe -a fileName=path/subfolder/filen

Doesn’t trigger the autocomplete.

Another issue - when the autocomplete does work, if I trigger it from the middle of a command while that I’m editing, the cursor ends up a few characters further on from the end of the filename (after selecting the autocomplete file) - rather than at the end of the filename, where I would expect it to be. It’s a minor detail, but it does feel odd.

elviskahoro commented 2 years ago

Describe the solution you'd like if I typed in desk and then tab. it should autocomplete to Desktop

In addition to this, shells like zsh will handle the case where if you type a subset of the folder and there's no other folder containing that subset, you can use tab autocomplete.

For example, in a home folder you may have

Desktop
Documents
Videos
Music
...

In this example typing cd top<TAB> should result in autofilling cd Desktop/, typing cd docu<TAB> should correct the spelling on the first character, etc. Would love to see this addition to Warp

DavidSouther commented 1 year ago

Hmm, this doesn't look like the same thing I brought up in #1954. That is an issue with the inline autosuggestions (which I understand to be ML generated?) are invalid for the working directory. (If these have the same underlying provider, and just get triggered differently, that's not indicated in the ticket. And it's not part of the ticket acceptance criteria that the paths be correct - a reasonable assumption, but I would have assumed that about the autosuggestions before I encountered that issue.)

jakeonrails commented 1 year ago

I came here to leave a bug report that I have a folder called Downloads and when I type down + TAB the autocomplete doesn't figure it out. I have to go back and type Down + TAB which is really annoying.

dannyneira commented 1 year ago

Hey @jakeonrails Sorry to hear about this, I can't seem to reproduce it on my end, do you have "Open completions as you type" enabled? Is anything else bound to TAB? Are you using any unsupported completion plugin?

Please see my example below, both with and without "Completions as you type" enabled

https://user-images.githubusercontent.com/16809145/229890270-0ccdd302-d1a9-4f7f-9d25-16c575e57917.mp4