-
Notifications
You must be signed in to change notification settings - Fork 38.9k
VSCode preselects a wrong CompletionItem if there are multiple CompletionItem having preselect=true #98102
Copy link
Copy link
Closed
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugsuggestIntelliSense, Auto CompleteIntelliSense, Auto CompleteverifiedVerification succeededVerification succeeded
Milestone
Description
- VSCode Version: 1.45.1
- OS Version: Darwin x64 19.4.0
Steps to Reproduce:
- Add an extension which generates multiple completion items with
preselect=true
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
let sel:vscode.DocumentSelector = { scheme: 'file' };
let LanguageServerProvider = vscode.languages.registerCompletionItemProvider(sel, {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
let completionResult: vscode.CompletionItem[] = []
let a = new vscode.CompletionItem("a");
a.preselect = true;
a.filterText = "a"
a.sortText = "0";
let b = new vscode.CompletionItem("b");
b.preselect = true;
b.filterText = "b"
b.sortText = "00";
let c = new vscode.CompletionItem("c");
c.preselect = true;
c.filterText = "c"
c.sortText = "000";
completionResult.push(a, b, c);
return completionResult
}
}, " ", ".");
context.subscriptions.push(LanguageServerProvider);
}
export function deactivate() {}- Trigger auto-completion, vscode would always choose b as the preselected item:
Does this issue occur when all extensions are disabled?: No - it requires a completion extension
Expected behavior:
Vscode should preselect a
Possible cause:
vscode/src/vs/editor/contrib/suggest/suggestMemory.ts
Lines 24 to 41 in 7f49bf1
| select(model: ITextModel, pos: IPosition, items: CompletionItem[]): number { | |
| if (items.length === 0) { | |
| return 0; | |
| } | |
| let topScore = items[0].score[0]; | |
| for (let i = 1; i < items.length; i++) { | |
| const { score, completion: suggestion } = items[i]; | |
| if (score[0] !== topScore) { | |
| // stop when leaving the group of top matches | |
| break; | |
| } | |
| if (suggestion.preselect) { | |
| // stop when seeing an auto-select-item | |
| return i; | |
| } | |
| } | |
| return 0; | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugsuggestIntelliSense, Auto CompleteIntelliSense, Auto CompleteverifiedVerification succeededVerification succeeded
