Is it possible to execute another extension’s code action programmatically from my VSCode extension? Specifically I need to run the resolveCodeAction
of the code action provider before executing, which seems to be what VSCode does before running a Quick Fix.
Most posts that I have seen outline something like this:
const diagnostics = vscode.languages.getDiagnostics(document.uri);
for (const diagnostic of diagnostics) {
const { range } = diagnostic;
// Get the quick fixes for the current diagnostic
const codeActions = await vscode.commands.executeCommand<vscode.CodeAction[]>(
'vscode.executeCodeActionProvider',
document.uri,
range,
vscode.CodeActionKind.QuickFix.value
);
if (codeActions && codeActions.length > 0) {
// Apply the first quick fix
await vscode.commands.executeCommand(
codeActions[0].command.command,
...codeActions[0].command.arguments
);
}
}
However, through experimentation it seems that vscode.executeCodeActionProvider
only runs the provideCodeAction
step of the interface, and not the resolveCodeAction
step for the resolved actions.
To be concrete, I am trying to run the bundled typescript-language-features
extensions "_typescript.applyFixAllCodeAction"
.
Is there a preferred way to execute CodeActions to emulate the way VSCode handles them internally?