PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 488 forks source link

Prioritize PowerShell autocomplete to top of suggestions list #4352

Open JustinGrote opened 1 year ago

JustinGrote commented 1 year ago

Prerequisites

Summary

Powershell has a completion API for commands that prioritizes things such as camelcase letters. For instance the first completion for g-arg is Get-AzureResourceGroup.

If possible, we should use this API and prioritize those results to the top of the list, rather than the default lexical search vscode does. This will more closely match the editor experience to the shell experience. image

TBD whether this should be the default behavior or an opt-in, but either way it should be controllable via a setting.

Proposed Design

No response

kilasuit commented 1 year ago

Agreed

By default it should be closest match but then ideally order by next closest match, especially if there is potential for only a partial abbreviation to have been provided.

JustinGrote commented 1 year ago

Right, order by autocomplete matches and then sort the vscode lexical recommendations to the bottom. This should of course be configurable with a setting for people who prefer the other way.

SeeminglyScience commented 1 year ago

afaik we don't have any control over this specifically. We return it in the order PowerShell gives it to us, and VSCode may decide to do something different.

That said, PowerShell's initial-complete functionality probably doesn't work properly in VSCode. The way completions work in a performant way in vsc is we give completions, then we return a list of results, then vsc banks those completions and as you type it filters them.

For example, you're probably still filtering the results of completing g-. There's some control there were we can mark results as "incomplete", but in this instance we would likely have to do it for every character which may take a large perf hit. You can test this by cancelling out of the completion menu entirely, and triggering it again with Ctrl + Space

Another issue is that we tell VSCode what the filter should be. So an easy to understand example:

Code to complete: "$PSScriptRoot\something.ps PowerShell says: "C:\User\user\Documents\Modules\etc\something.ps1" We tell VSCode: "C:\User\user\Documents\Modules\etc\something.ps1" VSCode says: "$PSScriptRoot\something.ps doesn't match "C:\User\user\Documents\Modules\etc\something.ps1" so hide it

That's a larger problem we need to figure out a way around in general. Hopefully there's an easy pattern I'm not seeing, but resolving that in a general sense might require adding a FilterText field to SMA.CompletionResult since the engine is the only thing that knows what part turned into what.