[Bug] suggestions are sometimes not properly ordered by sortText
See original GitHub issueReproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Code
monaco.languages.registerCompletionItemProvider('sql', {
provideCompletionItems: function (model, position) {
return {
triggerCharacters: ["."],
"suggestions": [
{
"insertText": "event_id",
"sortText": "1",
"kind": 14,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "event_id",
"documentation": "Column in my_fake_table_name_1234",
"label": {
"label": "event_id",
"description": "column in my_fake_table_name_1234"
}
},
{
"insertText": "get_events",
"sortText": "3",
"kind": 1,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "mock detail",
"documentation": "mock documentation",
"label": {
"label": "get_events",
"description": "mock description"
}
},
{
"insertText": "client_event_id",
"sortText": "2",
"kind": 14,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "client_event_id",
"documentation": "Column in my_fake_table_name_1234",
"label": {
"label": "client_event_id",
"description": "column in my_fake_table_name_1234"
}
},
]
}
}
});
monaco.editor.create(document.getElementById('container'), {
value: 'select * from my_fake_table_name_1234 where e',
language: 'sql'
});
Actual Behavior
Order:
event_id
get_events
client_event_id
Expected Behavior
Order:
event_id
client_event_id
get_events
Additional Context
I expect the sortText
parameter to drive the order that results are displayed and, for the most part, this seems to be the case. There does however seem to be some edge cases that cause the suggestions to not be displayed in alphabetical order according to their sortText
.
It seems like maybe there are multiple heuristics influencing the sorting. In this case, updating the label
->label
of the last suggestion to foo_event_id
seems to cause them to be ordered correctly, though I’m not sure why. The docs mention that label
is used if the sortText
value is falsy, but that isn’t the case here.
Playground for that:
monaco.languages.registerCompletionItemProvider('sql', {
provideCompletionItems: function (model, position) {
return {
triggerCharacters: ["."],
"suggestions": [
{
"insertText": "event_id",
"sortText": "1",
"kind": 14,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "event_id",
"documentation": "Column in my_fake_table_name_1234",
"label": {
"label": "event_id",
"description": "column in my_fake_table_name_1234"
}
},
{
"insertText": "get_events",
"sortText": "3",
"kind": 1,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "mock detail",
"documentation": "mock documentation",
"label": {
"label": "get_events",
"description": "mock description"
}
},
{
"insertText": "client_event_id",
"sortText": "2",
"kind": 14,
"range": {
"startLineNumber": 1,
"endLineNumber": 1,
"startColumn": 45,
"endColumn": 46
},
"detail": "client_event_id",
"documentation": "Column in my_fake_table_name_1234",
"label": {
"label": "FOO_event_id",
"description": "column in my_fake_table_name_1234"
}
},
]
}
}
});
monaco.editor.create(document.getElementById('container'), {
value: 'select * from my_fake_table_name_1234 where e',
language: 'sql'
});
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Completion filtering and sorting · Issue #898 - GitHub
The response to a completion request should specify whether or not the completion list has already been filtered and sorted by the server....
Read more >Text not sorting correctly - Excel - Microsoft Tech Community
I have one spreadsheet with 2 columns and 555 rows - I have made sure I have no leading spaces, no hidden rows...
Read more >Watch your sort and other Excel traps for the unwary
ALWAYS check that Excel has correctly converted text to numbers. ... If you try to sort text that seem to be numbers, Excel...
Read more >Jinja2: sort text lines in alphabetical order in .j2 template?
One possible solution: Create a first to_sort.j2 template: Hello, this is line 1 Actually, this second line should be first {{ line_name }} ......
Read more >Does sort support sorting a file in-place, like `sed --in-place`?
sort has the -o (or --output ) option that takes a filename as argument. The program writes the data to a temporary file,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, there is no way to enforce a constant sort order. It’s the user input that resorts and they do it by typing matching prefixes.
A completion item provider is invoked, returns completions but they don’t show up! 😕 What’s the issue? Filtering! Filtering compares completions with a prefix and hides those that don’t match.
Example
say.he|
(|
is the cursor)abc
,help
,hood
he
-prefix and scores it againstabc
,help
, andhood
.abc
- no match, don’t showhelp
- good match, showhood
- no match, onlyh
occurs, don’t showhelp
suggestion, does not showabc
andhood
suggestionExtensions Rule!
The above sample was using “defaults” to determine the prefix and the filter criteria.
prefix:
each completion can define its very own prefix viavscode.CompletionItem#range
. Taking the example above, valid prefixes can besay.he
or.he
orfilter:
each completion can define what string to use when filtering. The default is the label but viavscode.CompletionItem#filterText
any string can be definedWhen to use what? It depends on the language, its word definition, and if you control/understand the word definition or not. The defaults usually work well enough but some languages might use a non-intuitive word definition, or completions span multiple words, or completions include non-word character etc. In all those cases the
range
-property should be used.