microsoft / microsoft/vscode

vs.commands.executeCommand("vscode.executeCodeActionProvider") loses keepWhitespace field from SnippetTextEdits

Open
#325,990 0 comments 0 reactions 1 assignee Claimed by @amunger View on GitHub
stale triage-needed
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

In my extension I created a codeActionsProvider that returns a`WorkspaceEdit` that contains a `SnippetTextEdit` with `keepWorkspace=true`:

```ts
vs.languages.registerCodeActionsProvider({ scheme: "file" }, {
provideCodeActions(_document, _range, _context, _token) {
const snippet = new vs.SnippetTextEdit(
new vs.Range(
new vs.Position(0, 0),
new vs.Position(0, 0),
),
new vs.SnippetString("${1:widget}"),
);
snippet.keepWhitespace = true;
const edit = new vs.WorkspaceEdit();
edit.set(vs.Uri.parse("foo://foo"), [[snippet, undefined]]);

const action = new vs.CodeAction("My Action");
action.edit = edit;
return [
action
];
},
});
```

If, in a test, I call `vs.commands.executeCommand("vscode.executeCodeActionProvider")` like this:

```ts
const actions = await vs.commands.executeCommand("vscode.executeCodeActionProvider", flutterEmptyFile, new vs.Range(new vs.Position(0, 0), new vs.Position(0, 0)));
```

The `keepWhitespace` flag gets lost, and if I then use `vs.workspace.applyEdit()` on it, the whitespace is not kept (instead, VS Code changes it, believing the returned action didn't already have the correct whitespace).

Here's what inspecting the edit looks like in the extension side:

Image

And here's what it looks like on the test side:

Image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.