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

when comparing suggestions then use their textLabel #153283

Merged
merged 1 commit into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/suggest/browser/suggest.ts
Expand Up @@ -323,9 +323,9 @@ function defaultComparator(a: CompletionItem, b: CompletionItem): number {
}
}
// check with 'label'
if (a.completion.label < b.completion.label) {
if (a.textLabel < b.textLabel) {
return -1;
} else if (a.completion.label > b.completion.label) {
} else if (a.textLabel > b.textLabel) {
return 1;
}
// check with 'type'
Expand Down
15 changes: 13 additions & 2 deletions src/vs/editor/contrib/suggest/test/browser/completionModel.test.ts
Expand Up @@ -10,13 +10,13 @@ import { CompletionModel } from 'vs/editor/contrib/suggest/browser/completionMod
import { CompletionItem, getSuggestionComparator, SnippetSortOrder } from 'vs/editor/contrib/suggest/browser/suggest';
import { WordDistance } from 'vs/editor/contrib/suggest/browser/wordDistance';

export function createSuggestItem(label: string, overwriteBefore: number, kind = languages.CompletionItemKind.Property, incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }, sortText?: string, filterText?: string): CompletionItem {
export function createSuggestItem(label: string | languages.CompletionItemLabel, overwriteBefore: number, kind = languages.CompletionItemKind.Property, incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }, sortText?: string, filterText?: string): CompletionItem {
const suggestion: languages.CompletionItem = {
label,
sortText,
filterText,
range: { startLineNumber: position.lineNumber, startColumn: position.column - overwriteBefore, endLineNumber: position.lineNumber, endColumn: position.column },
insertText: label,
insertText: typeof label === 'string' ? label : label.label,
kind
};
const container: languages.CompletionList = {
Expand Down Expand Up @@ -275,6 +275,17 @@ suite('CompletionModel', function () {
assert.strictEqual(second.completion.label, '<- groups');
});

test('Completion item sorting broken when using label details #153026', function () {
const itemZZZ = createSuggestItem({ label: 'ZZZ' }, 0, languages.CompletionItemKind.Operator, false);
const itemAAA = createSuggestItem({ label: 'AAA' }, 0, languages.CompletionItemKind.Operator, false);
const itemIII = createSuggestItem('III', 0, languages.CompletionItemKind.Operator, false);

const cmp = getSuggestionComparator(SnippetSortOrder.Inline);
const actual = [itemZZZ, itemAAA, itemIII].sort(cmp);

assert.deepStrictEqual(actual, [itemAAA, itemIII, itemZZZ]);
});

test('Score only filtered items when typing more, score all when typing less', function () {
model = new CompletionModel([
createSuggestItem('console', 0),
Expand Down