Skip to content
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

Closed
rchande opened this issue Oct 3, 2017 · 18 comments
Closed

Feature Request: API support for autocomplete "preselection" #35551

rchande opened this issue Oct 3, 2017 · 18 comments
Assignees
Labels
api api-proposal feature-request Request for new features or functionality on-testplan suggest IntelliSense, Auto Complete
Milestone

Comments

@rchande
Copy link

rchande commented Oct 3, 2017

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 the new keyword when the type of the expected expression is List<string> (or whatever).
image

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.

@vscodebot vscodebot bot added the api label Oct 3, 2017
@rchande
Copy link
Author

rchande commented Oct 3, 2017

If this is something the team is interested in taking, I'm also happy to contribute this work--let me know.

@DustinCampbell
Copy link
Member

cc @jrieken

@jrieken jrieken self-assigned this Oct 4, 2017
@jrieken jrieken added the under-discussion Issue is under discussion for relevance, priority, approach label Oct 4, 2017
@jrieken
Copy link
Member

jrieken commented Oct 4, 2017

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

@DustinCampbell
Copy link
Member

@jrieken: Doesn't using sortText just end up re-sorting the list?

@jrieken
Copy link
Member

jrieken commented Oct 4, 2017

@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)

@rchande
Copy link
Author

rchande commented Oct 4, 2017

@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)?

a provider only has a local view of the world while a global view is needed to pick the one preselected item

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.

@jrieken
Copy link
Member

jrieken commented Oct 5, 2017

@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)?

Yes

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.

How would you know how well the user typed text matches a completion from another extension?

@rchande
Copy link
Author

rchande commented Dec 1, 2017

@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 think this is basically what VSCode does, except "providers" in VSCode are extensions that have registered completion support for a given language.

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.

@Novack
Copy link

Novack commented Dec 13, 2017

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.

@jrieken jrieken added feature-request Request for new features or functionality suggest IntelliSense, Auto Complete and removed under-discussion Issue is under discussion for relevance, priority, approach labels Dec 14, 2017
@jrieken jrieken added this to the June 2018 milestone Jun 8, 2018
@jrieken
Copy link
Member

jrieken commented Jun 11, 2018

For reference, Roslyn MatchPriority. For us that could translate into something similar, e.g. CompletionItem#preselect: number with similar semantics. Better names might be selectWeight, selectPriority, selectBoost matching the <verb><Subject>-pattern of sortText or filterText. Edit Likely better, preselect: boolean so that we don't have 'my number is bigger' fights...

@jrieken
Copy link
Member

jrieken commented Jun 11, 2018

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
}

@rchande
Copy link
Author

rchande commented Jun 18, 2018

@jrieken Awesome! Any idea when the extension API will support this?

@DanTup
Copy link
Contributor

DanTup commented Jun 18, 2018

@rchande The last two commits linked above look like they're adding it to the extension API (vscode.d.ts) and TypeScript impl :-)

@jrieken
Copy link
Member

jrieken commented Jun 18, 2018

@rchande In tomorrows insiders and with the June release in 3 weeks

@rchande
Copy link
Author

rchande commented Jun 18, 2018

@jrieken Cool, thanks!
@DanTup Reading? What's that 😄

@rchande
Copy link
Author

rchande commented Jun 19, 2018

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?

@jrieken
Copy link
Member

jrieken commented Jun 20, 2018

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 *

@MikhailArkhipov
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-proposal feature-request Request for new features or functionality on-testplan suggest IntelliSense, Auto Complete
Projects
None yet
Development

No branches or pull requests

6 participants