Skip to content

vscode.executeCompletionItemProvider results are missing additionalTextEdits #87346

Closed

Description

@DanTup

If you return additionalTextEdits in a completion item, the property is undefined when calling through vscode.executeCompletionItemProvider.

Setup:

const pos = new vscode.Position(0, 0);
const range = new vscode.Range(pos, pos);

context.subscriptions.push(vscode.languages.registerCompletionItemProvider({ language: "markdown" }, {
	provideCompletionItems: (document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) => {
		// Build a string like `test(onPressed: [null])` where [null] is
		// a placeholder containing "null".

		const item = new vscode.CompletionItem("dantup");
		item.insertText = "dantup";
		item.additionalTextEdits = [
			new vscode.TextEdit(range, "additional-dantup"),
		];
		return [item];
	}
}));

Test code:

const doc = await vscode.workspace.openTextDocument({ language: "markdown" });
const results = await (vscode.commands.executeCommand("vscode.executeCompletionItemProvider", doc.uri, pos, undefined, 100000) as Thenable<vscode.CompletionList>);
const result = results.items.find((c) => c.label === "dantup")!;
console.warn(result.label);
console.warn(result.additionalTextEdits);

Output is:

dantup
undefined

Full repro project is here:

https://github.com/DanTup/vscode-repro-completion-additional-edits

Activity

  1. added
    bug
    help wanted
    suggest
    on Dec 20, 2019
  2. jzyrobert commented on Dec 24, 2019

    @jzyrobert
    Contributor

    Johannes Rieken (@jrieken) It looks like the conversion here is missing.

    The doc states that additionalTextEdits should not overlap with the main edit range or each other, should that be checked or is that done when the edits are carried out?

    Adding this:
    Code_2019-12-24_00-11-11
    works, unless the range intersections need to be checked.

  3. jrieken commented on Dec 24, 2019

    @jrieken
    Contributor

    No checks required - this is already the way back from the UX and check should have been carried out already

  4. locked and limited conversation to collaborators on Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apibughelp wantedsuggest

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions