Can I trigger another extension's code action programmatically from my VSCode extension? Specifically, I want to execute the resolveCodeAction
of the code action provider before running it, similar to how VSCode handles Quick Fixes.
Most resources suggest a method like this:
const diagnostics = vscode.languages.getDiagnostics(document.uri);
for (const diagnostic of diagnostics) {
const { range } = diagnostic;
// Retrieve 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, after testing, it appears that vscode.executeCodeActionProvider
only executes the provideCodeAction
step and not the resolveCodeAction
step for resolved actions.
I specifically aim to trigger the bundled typescript-language-features
extension's
"_typescript.applyFixAllCodeAction"
.
Is there a recommended approach to triggering CodeActions to replicate how VSCode internally manages them?
EDIT: This question differs from 'Add all missing imports' shortcut; I am inquiring about programmatically executing this action as a VSCode extension developer, not as a user of VSCode.