AI quickFix noImplicitAny: replaces inferFromUsage

This commit is contained in:
Nathan Shively-Sanders
2023-07-06 13:11:17 -07:00
parent c9fd01215d
commit 5e72826c4c
2 changed files with 13 additions and 13 deletions

View File

@@ -340,23 +340,12 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
}
for (const tsCodeFix of response.body) {
this.addAllFixesForTsCodeAction(results, document, file, diagnostic, tsCodeFix as Proto.CodeFixAction);
results.addAction(this.getSingleFixForTsCodeAction(document, diagnostic, tsCodeFix));
this.addFixAllForTsCodeAction(results, document.uri, file, diagnostic, tsCodeFix as Proto.CodeFixAction);
}
return results;
}
private addAllFixesForTsCodeAction(
results: CodeActionSet,
document: vscode.TextDocument,
file: string,
diagnostic: vscode.Diagnostic,
tsAction: Proto.CodeFixAction
): CodeActionSet {
results.addAction(this.getSingleFixForTsCodeAction(document, diagnostic, tsAction));
this.addFixAllForTsCodeAction(results, document.uri, file, diagnostic, tsAction as Proto.CodeFixAction);
return results;
}
private getSingleFixForTsCodeAction(
document: vscode.TextDocument,
diagnostic: vscode.Diagnostic,
@@ -367,6 +356,16 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
if (aiQuickFixEnabled && tsAction.fixName === fixNames.classIncorrectlyImplementsInterface) {
followupAction = new EditorChatFollowUp('Implement the class using the interface', document, diagnostic.range, this.client);
}
else if (aiQuickFixEnabled && tsAction.fixName === fixNames.inferFromUsage) {
// TODO: "this code" is not specific; not sure if that's important
// TODO: Only fires when noImplicitAny is an error
// TODO: Seems to replace the inferFromUsage codefix, which is OK by me but maybe not the best.
// TODO: Doesn't fire in JS files? Not sure.
// TODO: The span for inferFromUsage is smaller than a correct span..and copilot seems to ignore the span anyway.
// TODO: When there are "enough" types around, leave off the "Add separate interfaces when possible" because it's not helpful.
// TODO: It would be nice to fire on other errors
followupAction = new EditorChatFollowUp('Add types to this code. Add separate interfaces when possible. Do not change the code except for adding types.', document, diagnostic.range, this.client);
}
const codeAction = new VsCodeCodeAction(tsAction, tsAction.description, vscode.CodeActionKind.QuickFix);
codeAction.edit = getEditForCodeAction(this.client, tsAction);
codeAction.diagnostics = [diagnostic];

View File

@@ -16,5 +16,6 @@ export const fixImport = 'import';
export const forgottenThisPropertyAccess = 'forgottenThisPropertyAccess';
export const removeUnnecessaryAwait = 'removeUnnecessaryAwait';
export const spelling = 'spelling';
export const inferFromUsage = 'inferFromUsage';
export const unreachableCode = 'fixUnreachableCode';
export const unusedIdentifier = 'unusedIdentifier';