Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

VSCode preselects a wrong CompletionItem if there are multiple CompletionItem having preselect=true #98102

Closed
HaoboGu opened this issue May 18, 2020 · 0 comments · Fixed by #98127
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug suggest IntelliSense, Auto Complete verified Verification succeeded
Milestone

Comments

@HaoboGu
Copy link
Contributor

HaoboGu commented May 18, 2020

  • VSCode Version: 1.45.1
  • OS Version: Darwin x64 19.4.0

Steps to Reproduce:

  1. 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() {}
  1. 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:

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;
}

@jrieken jrieken self-assigned this May 19, 2020
@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug suggest IntelliSense, Auto Complete labels May 19, 2020
@jrieken jrieken added this to the May 2020 milestone May 19, 2020
jrieken added a commit that referenced this issue May 19, 2020
@connor4312 connor4312 added the verified Verification succeeded label Jun 4, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Issue identified by VS Code Team member as probable bug suggest IntelliSense, Auto Complete verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants