vscode: CompletionItem commands no longer work if added during resolve (regression)
This code produces a completion item and adds a command
during resolve (which just shows an alert).
In the latest VS Code, this command does not fire when the completion item is selected, unless it is attached in the original provideCompletionItems
call.
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('vscode-repro-completion-commands.helloWorld', () => {
vscode.window.showInformationMessage('Hello World from vscode-repro-completion-commands!');
}));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
{ scheme: 'file' },
{
provideCompletionItems(doc, pos, token) {
const completionItem = new vscode.CompletionItem("ProcessResult");
// Attaching the command here works:
// completionItem.command = {
// command: "vscode-repro-completion-commands.helloWorld",
// title: "add imports",
// };
return new vscode.CompletionList(
[completionItem],
false,
);
},
resolveCompletionItem(oldItem) {
const completionItem = new vscode.CompletionItem("ProcessResult");
// Attaching the command here does not work.
completionItem.command = {
command: "vscode-repro-completion-commands.helloWorld",
title: "add imports",
};
return completionItem;
}
},
));
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 30 (30 by maintainers)
Commits related to this issue
- Temporarily skip test See https://github.com/Dart-Code/Dart-Code/issues/4583 See https://github.com/microsoft/vscode/issues/184924 — committed to Dart-Code/Dart-Code by DanTup a year ago
- also report late commands as deprecated API but let it slip through for now https://github.com/microsoft/vscode/issues/184924 — committed to microsoft/vscode by jrieken a year ago
I actually think that, if we could change the text edit during resolve, it should be doable (we may want to change more than just the text, for example changing whether the edit is a template or what the range of the edit is). In other words, we’re using it as a workaround for lazily resolving the entire
textEdit
, not just the text.Btw, it also seems odd that mutating the provided completion item during resolve works. I could patch that into the LSP middleware to “fix” my issue for now, but presumable it’s a bug.
I do hope you’ll reconsider this though (or at least give language servers/SDKs time to update). I feel like the issue it causes is far worse then the problem it’s solving (like I said, I’ve had zero complaints about it not working, because realistically it’s probably incredibly rare), and the refactor to work differently isn’t trivial.