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:
Matt Bierner
2018-01-22 11:45:22 -08:00
committed by GitHub
parent 8f58711d82
commit eccf728e64
18 changed files with 372 additions and 41 deletions

View File

@@ -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;
}
}