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

Completions ignores sortText #109067

Closed
boaz-codota opened this issue Oct 21, 2020 · 11 comments
Closed

Completions ignores sortText #109067

boaz-codota opened this issue Oct 21, 2020 · 11 comments
Assignees
Labels
*dev-question VS Code Extension Development Question suggest IntelliSense, Auto Complete

Comments

@boaz-codota
Copy link

boaz-codota commented Oct 21, 2020

  • 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

@jrieken jrieken added the suggest IntelliSense, Auto Complete label Oct 21, 2020
@boaz-codota
Copy link
Author

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

@jrieken
Copy link
Member

jrieken commented Oct 21, 2020

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 🤔

@boaz-codota
Copy link
Author

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

@jrieken
Copy link
Member

jrieken commented Oct 21, 2020

Found the issue: #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?

@boaz-codota
Copy link
Author

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

@jrieken
Copy link
Member

jrieken commented Oct 21, 2020

Check this out:

vscode/src/vs/vscode.d.ts

Lines 3855 to 3863 in cb1dce0

*
* Note that `sortText` is only used for the initial ordering of completion
* items. When having a leading word (prefix) ordering is based on how
* well completion match that prefix and the initial ordering is only used
* when completions match equal. The prefix is defined by the
* [`range`](#CompletionItem.range)-property and can therefore be different
* for each completion.
*/
sortText?: string;

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.

@jrieken
Copy link
Member

jrieken commented Oct 21, 2020

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

@boaz-codota
Copy link
Author

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

@jrieken
Copy link
Member

jrieken commented Oct 22, 2020

Hard to say. What does the explain widget say?

@boaz-codota
Copy link
Author

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

@jrieken
Copy link
Member

jrieken commented Oct 22, 2020

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

@jrieken jrieken closed this as completed Oct 26, 2020
@jrieken jrieken added the *dev-question VS Code Extension Development Question label Oct 26, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*dev-question VS Code Extension Development Question suggest IntelliSense, Auto Complete
Projects
None yet
Development

No branches or pull requests

2 participants