-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: API support for autocomplete "preselection" #35551
Comments
If this is something the team is interested in taking, I'm also happy to contribute this work--let me know. |
cc @jrieken |
It's not that simple with the VS Code model and that's because multiple extensions can provide extensions and the UI merges then. That model makes all "absolute" behaviour hard to get right because a provider only has a local view of the world while a global view is needed to pick the one preselected item. Still, you can achieve this by utilising the 'sortText'-property. The VSCode UI always sorts the completion list by "rank" (in contrast to VS which selects the best match). These "ranks" are computed by looking at the text left of the cursor or, when there is no text, by using the 'sortText'-property |
@jrieken: Doesn't using sortText just end up re-sorting the list? |
Only once when all completions are brought together. We will then show completions in that order but as soon as the user types (with the completion window open) we constantly resort item on "how well they match". When two item match equally well we fallback to their original rank (based on sort-text) |
@jrieken If I use sortText, won't I be forcing the item I want to select to the top of the list (eg, not sorted alphabetically)?
We have code that handles this in Roslyn :). The main trick is making sure that preselection does not override matching based on what the user typed. |
Yes
How would you know how well the user typed text matches a completion from another extension? |
@jrieken Roslyn has a model where there are multiple "providers" that can provide completions at a given location in a C#/VB file. Each provider can mark its own items for preselection if it wants, and the engine that aggregates all of the results chooses the best item across all providers. I'm requesting that the VS Code API add a property onto completion items that says "I"m such a good item, that if the user hasn't typed anything, you should say that I'm the best match". This is a presentation mode that C# users depend on, so it would be nice we could provide it from Omnisharp-vscode. |
I just want to mention that this is really important to people coming from VS like myself, that expect small but relevant time savers like the one described in the op, to be present and on feature parity before moving into VSCode. |
For reference, Roslyn |
The internal implementation for this is ready. It will select the first preselected item of the group of best ranked items unless there is MRU information. Next step is exposing this in the extension API export class CompletionItem {
preselect?: boolean
} |
@jrieken Awesome! Any idea when the extension API will support this? |
@rchande The last two commits linked above look like they're adding it to the extension API (vscode.d.ts) and TypeScript impl :-) |
@rchande In tomorrows insiders and with the June release in 3 weeks |
Also @jrieken, when should we update the vscode npm package (https://www.npmjs.com/package/vscode/v/1.1.18) to get updated with the latest vscode.d.ts? |
It will need the stable release to work. Then simply set the engine version in your package.json file and run npm install. To test against insiders, you can simply copy the vscode.d.ts from our repo or temporary set the engine property to * |
Language server protocol needs to be updated as well. Currently it does not seem to copy the field over from external LS to the TS side of things. |
The Visual Studio for Windows text editor's completion API has a feature that allows languages that implement completion to set the item that is selected when the completion list first comes up. The C# language service in VS has used this to build various experiences that they call "preselection": namely, the completion list comes up when the user types SPACE and a useful item is already selected. The canonical example of this is preselecting items after
new
in C#.List<string>
is not normally present in the completion list, but gets specifically added preselected after thenew
keyword when the type of the expected expression isList<string>
(or whatever).It would be nice if VS Code could add a similar feature (perhaps by adding a "Preselect" bit to to the CompletionItem class). If this API were available, we would definitely consume it from omnisharp-vscode.
The text was updated successfully, but these errors were encountered: