vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Ship shell-agnostic terminal intellisense as a stable feature

Open davidthing opened this issue 1 year ago • 5 comments

Feature Request

https://github.com/microsoft/vscode/labels/terminal-suggest support for zsh and bash shells, similar to the existing support for Powershell:

image

Ideally, VS Code would pick up the completions that a user already configured for their terminal. As a zsh user (at work) and bash user (at home), I wouldn't mind if enabling this feature required some minimal .zshrc/.bashrc changes (we're used to that kind of thing). It also wouldn't be a deal-breaker if I needed to hit TAB to generate the list of completions, but it'd be nice to have the completions updated after each input change.

Motivation

Terminal completion pop-ups are a feature available in several newer terminals/IDE's like Warp, Fig/AmazonQ, and JetBrains/IntelliJ. I'm quite excited to see that VS Code is adding support for this! However, switching to pwsh isn't in the cards for me. Plus, my teammates all use either zsh or bash, and it's harder for me to sell the idea of using VS Code without this feature.

Beyond the obvious aesthetic improvement, having a pop-up, scrollable list of options can be quite helpful for long lists of completion options, such as git <TAB>:

zsh: do you wish to see all 141 possibilities (141 lines)?

Prior Work

PR https://github.com/microsoft/vscode/pull/211962 disabled the https://github.com/microsoft/vscode/labels/terminal-suggest feature for all shells except powershell. Therefore it seems not possible to use this feature for any other shells, even with an extension.

davidthing avatar Aug 25 '24 16:08 davidthing

This is now supported, but will keep it open to track the api-proposal and until we have support for fish #233799

meganrogge avatar Jan 27 '25 17:01 meganrogge

I'm glad to see that this feature is available on stable VS Code releases now! @meganrogge, do you have any more information about what "supported" means? In the docs, I only found reference to Powershell completions, so perhaps they haven't been updated yet? I'm hoping 🤞 that this sentence is outdated, since I use Linux as my daily driver at home:

Note: This functionality is currently only available on Windows and macOS.

I tried this feature on MacOS (version info below) and the completions don't seem to be working quite right. In zsh, the completion pop-up appears for a limited set of commands (ls, git) and when I hit the down key ⬇ on my keyboard, nothing happens — the top item remains selected. (Edit: that issue happened consistently, then mysteriously went away and I can't replicate it now 🤷.) In bash (v5.2), I can't get the completion pop-up to show up at all 🤔

Admittedly, I'm confused about how the completions are populated for terminals like zsh and bash. The docs only mention how the completions are generated for Powershell:

Behind the scenes, this functionality is powered by the PowerShell session's native completion API, so context-aware completions like variables are available.

In my feature request, I mused that "Ideally, VS Code would pick up the completions that a user already configured for their terminal." I can understand if the MVP of this feature was more limited, but it would be helpful to know the current process/limitations for customizing the completions.


VS Code version info on my Mac:

Version: 1.100.2 (Universal)
Commit: 848b80aeb52026648a8ff9f7c45a9b0a80641e2e
Date: 2025-05-14T21:47:40.416Z (6 days ago)
Electron: 34.5.1
ElectronBuildId: 11369351
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 23.6.0

davidthing avatar May 21 '25 14:05 davidthing

Hi, this is still a preview feature, but is working well for me on bash and zsh using macOS. Re the issue you cannot repro, I cannot repro that either.

I also cannot reproduce any issue with using the down arrow key to select suggestions. Maybe run the command Developer: Toggle Keyboard Shortcuts Troubleshooting to see what's stealing that keybinding?

We are using Fig specs and also fetching builtin commands and executables from your path to show in the suggestion list.

Image

Any errors in the dev tools console?

As for linux support, that's on our radar and going to try to look into it in June https://github.com/microsoft/vscode/issues/235331

meganrogge avatar May 21 '25 17:05 meganrogge

Thanks @meganrogge for the quick response and troubleshooting tip! I'll take a look later.

Do you know how the completions are populated? I'm wondering what I need to do to add more completions.

davidthing avatar May 21 '25 18:05 davidthing

You can't add your own completions - atm, we source these as I described from:

  • your $PATH executables
  • builtin commands for the shell (for example, in bash, we run compgen -b

meganrogge avatar May 21 '25 18:05 meganrogge

@meganrogge, aside from that initial hiccup, this feature has been working great for me so far! For file/directory completion like cd, I noticed a productivity boost right away.

I look forward to having Linux support (I subscribed to https://github.com/microsoft/vscode/issues/235331), and I wish that I could add my own completions somehow (I develop and use proprietary CLI tools).

But, I'm not complaining! I'm happy to have this, and I'm even happier to see it being actively developed! VS Code's terminal (especially the "in editor area") is a pleasure to use. Thanks for your hard work.

davidthing avatar May 28 '25 16:05 davidthing

We're aiming to enable this by default on Insider's in June

meganrogge avatar Jun 13 '25 14:06 meganrogge

@meganrogge Is this feature expected to work for Pseudoterminal-based terminals? I attempted to use this proposed API with my pseudo-terminal and was unable to get the provider to trigger completions. I used $ and . as my trigger characters if that matters.

isc-bsaviano avatar Jun 30 '25 11:06 isc-bsaviano

@isc-bsaviano no - this relies on shell integration working, so will only work for a subset of shells as specified in the setting description terminal.integrated.suggest.enabled.

meganrogge avatar Jun 30 '25 12:06 meganrogge

@isc-bsaviano the built-in suggestions likely won't ever work as @meganrogge mentioned.

However, and I haven't tested, but I don't think we block that particular case generally though. So if you have shell integration support in your Pseudoterminal and a terminal completion provider (proposed), I suspect it will come through as an undefined shell type and you could check the Terminal object to see if it's one of your terminals.

If that doesn't work, we should be able to make it happen.

Tyriar avatar Jun 30 '25 13:06 Tyriar

Thanks for clarifying @Tyriar. I am hoping to use the terminal completion provider for my Pseudoterminal. I do not expect any built-in completions to work for it. My terminal has HasRichCommandDetection=True and reports the sequences in the correct order. I have not adopted the nonce yet because #190253 is still open. Is the completion provider still on track to be finalized for the June iteration? If so I will try this again when the API is finalized.

isc-bsaviano avatar Jun 30 '25 13:06 isc-bsaviano

It won't be finalized for June, only the suggest feature enabled on Insiders with the built-in providers. @meganrogge speaking of which, we should try get the API finalized before or when we enable for stable.

Tyriar avatar Jun 30 '25 14:06 Tyriar

Thanks @Tyriar. Should I expect the proposed API to work for my terminal at this stage? I can open a new issue for that if it would be helpful. For reference, the implementation of my terminal can be found here: https://github.com/intersystems-community/vscode-objectscript/blob/master/src/commands/webSocketTerminal.ts

isc-bsaviano avatar Jun 30 '25 15:06 isc-bsaviano

@isc-bsaviano oh I forgot to link it but I tested and found the problem you're hitting: https://github.com/microsoft/vscode/issues/253011, hopefully you should be able to play with it soon as there's a WIP PR

Tyriar avatar Jun 30 '25 17:06 Tyriar

Thanks! Is the id in the terminal completion provider supposed to match the the id of the terminal profile in my extension's package.json? That property of the completion provider has no documentation in the current proposal .d.ts

isc-bsaviano avatar Jun 30 '25 17:06 isc-bsaviano

Good point, that should have a description. It does not have to match anything in your package.json.

meganrogge avatar Jun 30 '25 17:06 meganrogge

@isc-bsaviano the id isn't so important, that drives this UI when you ctrl+/ to diagnose completions:

Image

Gets reported in our telemetry so we can see usage stats:

https://github.com/microsoft/vscode/blob/23f24ddaf0f394344b869c3aea6277b064c8eb2f/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestTelemetry.ts#L117-L157

And is also the key in the terminal.integrated.suggest.providers setting. These are the defaults:

"terminal.integrated.suggest.providers": {
  "terminal-suggest": true,
  "pwsh-shell-integration": true,
  "lsp": true
},

You may also have to add your provider explicitly there as true, we haven't had much external experimentation with the API AFAIK.

Tyriar avatar Jun 30 '25 19:06 Tyriar

Thanks, that's really helpful. I will try this API out and provide feedback.

isc-bsaviano avatar Jun 30 '25 20:06 isc-bsaviano

Using the latest insiders I was able to get my provider to trigger for zsh after I added it to the "terminal.integrated.suggest.providers" object. It does not trigger for my Pseudoterminal yet though, which is expected.

isc-bsaviano avatar Jun 30 '25 21:06 isc-bsaviano

@isc-bsaviano should work for undefined shell types in the first 1.103 insiders: https://github.com/microsoft/vscode/issues/253011

Tyriar avatar Jul 07 '25 13:07 Tyriar

Will the fish shell be supported out of the box?

J3m5 avatar Sep 08 '25 09:09 J3m5

@J3m5 there is some support for fish: https://github.com/microsoft/vscode/blob/e44b0af9cc7a37367cbaa2bf3692abfa37628768/extensions/terminal-suggest/src/shell/fish.ts#L1-L92

However, we have telemetry on what shell types are used now and we've found fish users are actually a vocal minority, making up only around 0.2% of overall terminal launches. So we've decided to focus primarily on pwsh, bash and zsh going forward, leaving fish in particular to the community. The community actually contributed the majority of the shell integration script for fish as well https://github.com/microsoft/vscode/pull/157291

Tyriar avatar Sep 08 '25 12:09 Tyriar

@Tyriar @meganrogge Is this API still on track for finalization in this iteration? I've also noticed that completions for extension terminals are no longer working. I see #terminalCompletions Shell type undefined not supported in the Debug Console when running my extension in debug mode. I am on the following version:

Version: 1.105.0-insider Commit: afe5914687af530d501e7fa9000253ebf76ce9ed Date: 2025-09-25T05:05:49.513Z Electron: 37.3.1 ElectronBuildId: 12404162 Chromium: 138.0.7204.235 Node.js: 22.18.0 V8: 13.8.258.31-electron.0 OS: Darwin arm64 24.6.0

isc-bsaviano avatar Sep 25 '25 12:09 isc-bsaviano

which shell are you using when you see that message?

meganrogge avatar Sep 25 '25 17:09 meganrogge

It will not work unless you are using one of our supported shell types: https://github.com/microsoft/vscode/blob/cfc8af034cd01ce596b1e9003ed6150e0a77878e/extensions/terminal-suggest/src/terminalSuggestMain.ts#L525-L540

meganrogge avatar Sep 25 '25 17:09 meganrogge

Probably won't be finalized this iteration

meganrogge avatar Sep 25 '25 17:09 meganrogge

I'm using an extension terminal (Pseudoterminal), which Daniel enabled completions for in #253011

isc-bsaviano avatar Sep 25 '25 17:09 isc-bsaviano

can you pls enable terminal trace level logging and provide the logs when you request them?

Developer: Set Log Level -> Terminal -> Trace Show Output Channel -> Terminal

Image

meganrogge avatar Sep 25 '25 17:09 meganrogge

Note that you now have to pass an id in: https://github.com/microsoft/vscode/pull/266073

meganrogge avatar Sep 25 '25 17:09 meganrogge

That was my issue! I was using an outdated copy of the proposal. My provider is now being triggered. I did notice that it does not trigger every time a trigger character is typed. It seems like the first instance of the trigger character does not trigger a call.

isc-bsaviano avatar Sep 25 '25 17:09 isc-bsaviano