mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
CodeActionScope (#41782)
* Add CodeActionScope * Replace matches with contains, try using in ts extension * Move filtering to getCodeActions * Basic test * Docs * Fix tests * Hooking up requested scope * Add basic test for requestedScope * Added auto apply logic * Gate refactor provider to only compute refactorings when requested * Making suggested renames * Clean up code action trigger impl to use single Trrigger info object * Rename codeActionScope file and internal CodeActionScope class * Add quick fix base type * Make keybinding API more similar to insertSnippet Take args as an object instead of as an array of values * Clean up docs * scope -> kind * Fixing examples to match Refactor kind
This commit is contained in:
@@ -108,13 +108,17 @@ export default class TypeScriptRefactorProvider implements vscode.CodeActionProv
|
||||
public async provideCodeActions(
|
||||
document: vscode.TextDocument,
|
||||
_range: vscode.Range,
|
||||
_context: vscode.CodeActionContext,
|
||||
context: vscode.CodeActionContext,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.CodeAction[]> {
|
||||
if (!this.client.apiVersion.has240Features()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (context.only && !vscode.CodeActionKind.Refactor.contains(context.only)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!vscode.window.activeTextEditor) {
|
||||
return [];
|
||||
}
|
||||
@@ -146,7 +150,8 @@ export default class TypeScriptRefactorProvider implements vscode.CodeActionProv
|
||||
title: info.description,
|
||||
command: SelectRefactorCommand.ID,
|
||||
arguments: [document, file, info, range]
|
||||
}
|
||||
},
|
||||
kind: vscode.CodeActionKind.Refactor
|
||||
});
|
||||
} else {
|
||||
for (const action of info.actions) {
|
||||
@@ -156,7 +161,8 @@ export default class TypeScriptRefactorProvider implements vscode.CodeActionProv
|
||||
title: action.description,
|
||||
command: ApplyRefactoringCommand.ID,
|
||||
arguments: [document, file, info.name, action.name, range]
|
||||
}
|
||||
},
|
||||
kind: TypeScriptRefactorProvider.getKind(action)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -166,4 +172,11 @@ export default class TypeScriptRefactorProvider implements vscode.CodeActionProv
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private static getKind(refactor: Proto.RefactorActionInfo) {
|
||||
if (refactor.name.startsWith('function_')) {
|
||||
return vscode.CodeActionKind.RefactorExtract.append('function');
|
||||
}
|
||||
return vscode.CodeActionKind.Refactor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user