Vscode: Completions ignores sortText

Created on 21 Oct 2020  路  11Comments  路  Source: microsoft/vscode




  • VSCode Version: master
  • OS Version: ---

Building TabNine we encountered a bug in completions, where sortText is ignored if any CompletionItem does not contain sortText attribute. This causes the IDE to totally ignore the sortText in the ordering, forcing the sort algorithm to fallback to label only.

Steps to Reproduce:

  1. Use suggestions from a source that provide sortText (such TabNine) & a source that does not provide sortText (such the built in lsp).
  2. Completions suggestions's ordering will be based on the label and not on the sortText.

I traced the bug to this line:
https://github.com/microsoft/vscode/blob/master/src/vs/editor/contrib/suggest/suggest.ts#L274
The problem is that it is checked that sortText is present on both CompletionItems, breaking the sort functionality if any single item does not implement sortText.


Does this issue occur when all extensions are disabled?: Yes

*dev-question suggest

Most helpful comment

I think you need to trigger it first on an item with details, like realPath or so and then go up

All 11 comments

@jrieken I'll be more than happy to create a PR if it'll be merged

If it's a good PR it'll be merged. Tho, I wonder if there was a specific reason for why things are they way they are. I could have also sworn that I have fixed this already... Needs a short trip down memory lane before making this change 馃

Cool, let me know if you want me to provide a fix. Will ping every day. Thanks!

Found the issue: https://github.com/microsoft/vscode/issues/66109. So, this is actually fixed but in a sneaky way, e.g by always filling in the sortText-property (b4ead4e). Leaves the question what you are actually seeing? Do you have some simple steps to reproduce this?

This is an example:
image

We give our suggestions sortText of zeros (1st suggestions gets "0", 2nd "00" etc.; I also tried other characters combinations, none seem to change something) but our suggestions still only shown after some of the results coming from the lsp (not all of them, only those with the same Range of matching characters).

You can install TabNine and test it yourself.
This is where the sortText is set: https://github.com/codota/tabnine-vscode/blob/master/src/provideCompletionItems.ts#L95

Check this out: https://github.com/microsoft/vscode/blob/cb1dce0ef30d48c4259eb7d0a923926b3e6e16af/src/vs/vscode.d.ts#L3855-L3863

Basically, what is says (tries to say) is that once a prefix exists (ht in your sample) the match quality of that prefix and a suggestion overrules all sortText.

Unsure if you use filterText. With that property you can provide a string that matched against said prefix. Assuming in your sample you set it to html then ranking should be different. Also: you can hit cmd+/ to toggle explain mode - the details part of the suggest widget will then show some debug info, like so:
Screenshot 2020-10-21 at 18 01 04

Thanks! That seem to make things much better. But I'm still confused about other ordering as such:
image

Hard to say. What does the explain widget say?

cmd+/ didn't trigger it. Do I need some special version of vscode for it?

I think you need to trigger it first on an item with details, like realPath or so and then go up

Was this page helpful?
0 / 5 - 0 ratings