Add more complex options

This commit is contained in:
Nathan Shively-Sanders
2023-09-14 11:23:16 -07:00
parent b1b350626f
commit d1d6055aa5
4 changed files with 65 additions and 20 deletions

View File

@@ -331,23 +331,23 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
};
actions.push(codeAction);
if (vscode.workspace.getConfiguration('typescript').get('experimental.aiQuickFix')) {
if (vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions')) {
let message: string | undefined;
let expand: Expand | undefined;
if (action.fixName === fixNames.classIncorrectlyImplementsInterface) {
if (action.fixName === fixNames.classIncorrectlyImplementsInterface && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.classIncorrectlyImplementsInterface') !== false) {
message = `Implement the stubbed-out class members for ${document.getText(diagnostic.range)} with a useful implementation.`;
expand = { kind: 'code-action', action };
}
else if (action.fixName === fixNames.fixClassDoesntImplementInheritedAbstractMember) {
else if (action.fixName === fixNames.fixClassDoesntImplementInheritedAbstractMember && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.classDoesntImplementInheritedAbstractMember') !== false) {
message = `Implement the stubbed-out class members for ${document.getText(diagnostic.range)} with a useful implementation.`;
expand = { kind: 'code-action', action };
}
else if (action.fixName === fixNames.fixMissingFunctionDeclaration) {
else if (action.fixName === fixNames.fixMissingFunctionDeclaration && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.missingFunctionDeclaration') !== false) {
message = `Provide a reasonable implementation of the function ${document.getText(diagnostic.range)} given its type and the context it's called in.`;
expand = { kind: 'code-action', action };
}
else if (action.fixName === fixNames.inferFromUsage) {
else if (action.fixName === fixNames.inferFromUsage && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.inferAndAddTypes') !== false) {
const inferFromBody = new VsCodeCodeAction(action, 'Copilot: Infer and add types', vscode.CodeActionKind.QuickFix);
inferFromBody.edit = new vscode.WorkspaceEdit();
inferFromBody.diagnostics = [diagnostic];
@@ -362,7 +362,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
};
actions.push(inferFromBody);
}
else if (action.fixName === fixNames.addNameToNamelessParameter) {
else if (action.fixName === fixNames.addNameToNamelessParameter && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.addNameToNamelessParameter') !== false) {
const newText = action.changes.map(change => change.textChanges.map(textChange => textChange.newText).join('')).join('');
message = `Rename the parameter ${newText} with a more meaningful name.`;
expand = {

View File

@@ -574,18 +574,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
codeAction = new MoveToFileCodeAction(document, action, rangeOrSelection);
} else {
let copilotRename: ((info: Proto.RefactorEditInfo) => vscode.Command) | undefined;
if (vscode.workspace.getConfiguration('typescript', null).get('experimental.aiQuickFix')) {
if (Extract_Constant.matches(action)
|| Extract_Function.matches(action)
|| Extract_Type.matches(action)
|| Extract_Interface.matches(action)
|| action.name.startsWith('Infer function return')) {
if (vscode.workspace.getConfiguration('typescript', null).get('experimental.aiCodeActions')) {
if (Extract_Constant.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractConstant') !== false
|| Extract_Function.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractFunction') !== false
|| Extract_Type.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractType') !== false
|| Extract_Interface.matches(action) && vscode.workspace.getConfiguration('typescript').get('experimental.aiCodeActions.extractInterface') !== false) {
const newName = Extract_Constant.matches(action) ? 'newLocal'
: Extract_Function.matches(action) ? 'newFunction'
: Extract_Type.matches(action) ? 'NewType'
: Extract_Interface.matches(action) ? 'NewInterface'
: action.name.startsWith('Infer function return') ? 'newReturnType'
: '';
: '';
copilotRename = info => ({
title: '',
command: EditorChatFollowUp.ID,