mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Prototype auto fixable quick fixes
Part of #62110 - Adds a new field `canAutoApply` to code actions. This field indicates that a code action can be applied without additional user input. For quick fixes, this should be set if the fix properly addresses the error - Enable auto fixes for TS spelling errors - Added a `editor.action.autoFix` command to triggers auto fixes at the current cursor position
This commit is contained in:
@@ -240,7 +240,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
|
||||
const results = new CodeActionSet();
|
||||
for (const tsCodeFix of response.body) {
|
||||
this.addAllFixesForTsCodeAction(results, document, file, diagnostic, tsCodeFix);
|
||||
this.addAllFixesForTsCodeAction(results, document, file, diagnostic, tsCodeFix as Proto.CodeFixAction);
|
||||
}
|
||||
return results.values;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
document: vscode.TextDocument,
|
||||
file: string,
|
||||
diagnostic: vscode.Diagnostic,
|
||||
tsAction: Proto.CodeAction
|
||||
tsAction: Proto.CodeFixAction
|
||||
): CodeActionSet {
|
||||
results.addAction(this.getSingleFixForTsCodeAction(diagnostic, tsAction));
|
||||
this.addFixAllForTsCodeAction(results, document, file, diagnostic, tsAction as Proto.CodeFixAction);
|
||||
@@ -259,7 +259,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
|
||||
private getSingleFixForTsCodeAction(
|
||||
diagnostic: vscode.Diagnostic,
|
||||
tsAction: Proto.CodeAction
|
||||
tsAction: Proto.CodeFixAction
|
||||
): vscode.CodeAction {
|
||||
const codeAction = new vscode.CodeAction(tsAction.description, vscode.CodeActionKind.QuickFix);
|
||||
codeAction.edit = getEditForCodeAction(this.client, tsAction);
|
||||
@@ -269,6 +269,9 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
arguments: [tsAction],
|
||||
title: ''
|
||||
};
|
||||
if (tsAction.fixName === 'spelling') {
|
||||
codeAction.canAutoApply = true;
|
||||
}
|
||||
return codeAction;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user