Rest of useful codefixes

Initial hacky versions only
This commit is contained in:
Nathan Shively-Sanders
2023-08-31 16:15:04 -07:00
parent 2aaf53bc41
commit 63c84d3aab
3 changed files with 26 additions and 11 deletions

View File

@@ -327,6 +327,18 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
if(tsAction.fixName === fixNames.classIncorrectlyImplementsInterface) {
followupAction = new EditorChatFollowUp('Implement the class using the interface', document, diagnostic.range, this.client);
}
else if(tsAction.fixName === fixNames.fixClassDoesntImplementInheritedAbstractMember) {
// TODO: This range has the same problem as all the other followups
followupAction = new EditorChatFollowUp('Implement abstract class members with a useful implementation', document, diagnostic.range, this.client);
}
else if (tsAction.fixName === fixNames.fixMissingFunctionDeclaration) {
let edits = getEditForCodeAction(this.client, tsAction)
// console.log(JSON.stringify(edits)) // need to generate a new range based on the length and lines of the new text
const range = !edits ? diagnostic.range : edits.entries()[0][1][0].range
followupAction = new EditorChatFollowUp(
`Implement the function based on the function call \`${document.getText(diagnostic.range)}\``,
document, range, this.client);
}
else if (tsAction.fixName === fixNames.inferFromUsage) {
const inferFromBody = new VsCodeCodeAction(tsAction, 'Copilot: Infer and add types', vscode.CodeActionKind.QuickFix);
inferFromBody.edit = new vscode.WorkspaceEdit();
@@ -342,7 +354,6 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCode
actions.push(inferFromBody);
}
else if (tsAction.fixName === fixNames.addNameToNamelessParameter) {
followupAction = new EditorChatFollowUp('Suggest a better name for this parameter', document, diagnostic.range, this.client);
const suggestName = new VsCodeCodeAction(tsAction, 'Add parameter name', vscode.CodeActionKind.QuickFix);
suggestName.edit = getEditForCodeAction(this.client, tsAction);
suggestName.command = {

View File

@@ -596,19 +596,21 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
} else {
let bonus: vscode.Command | undefined
if (vscode.workspace.getConfiguration('typescript', null).get('experimental.aiQuickFix')) {
if (action.name.startsWith('constant_')
|| action.name.startsWith('function_')
|| action.name.startsWith('Extract to')
|| action.name.startsWith('Infer function return')) {
const kind = action.name.startsWith('constant_') ? 'expression'
: action.name.startsWith('function_') ? 'function'
: action.name.startsWith('Extract to') ? 'type'
: action.name.startsWith('Infer function return') ? 'type'
: 'code';
if (Extract_Constant.matches(action)
|| Extract_Function.matches(action)
|| Extract_Type.matches(action)
|| Extract_Interface.matches(action)
|| action.name.startsWith('Infer function return')) { // TODO: There's no CodeActionKind for infer function return; maybe that's why it doesn't work
const kind = Extract_Constant.matches(action) ? 'variable'
: Extract_Function.matches(action) ? 'function'
: Extract_Type.matches(action) ? 'type'
: Extract_Interface.matches(action) ? 'type'
: action.name.startsWith('Infer function return') ? 'return type'
: '';
bonus = {
command: ChatPanelFollowup.ID,
arguments: [<ChatPanelFollowup.Args>{
prompt: `Suggest 5 names for the ${kind}
prompt: `Suggest 5 ${kind} names for the code below:
\`\`\`
${document.getText(rangeOrSelection)}.
\`\`\` `,

View File

@@ -18,5 +18,7 @@ export const removeUnnecessaryAwait = 'removeUnnecessaryAwait';
export const spelling = 'spelling';
export const inferFromUsage = 'inferFromUsage';
export const addNameToNamelessParameter = 'addNameToNamelessParameter';
export const fixMissingFunctionDeclaration = 'fixMissingFunctionDeclaration';
export const fixClassDoesntImplementInheritedAbstractMember = 'fixClassDoesntImplementInheritedAbstractMember';
export const unreachableCode = 'fixUnreachableCode';
export const unusedIdentifier = 'unusedIdentifier';