提交 69263017 编写于 作者: M Matt Bierner

Documenting more js/ts refactorings

上级 fe593912
......@@ -896,6 +896,21 @@
"title": "%codeActions.refactor.extract.type.title%",
"description": "%codeActions.refactor.extract.type.description%"
},
{
"kind": "refactor.rewrite.import",
"title": "%codeActions.refactor.rewrite.import.title%",
"description": "%codeActions.refactor.rewrite.import.description%"
},
{
"kind": "refactor.rewrite.export",
"title": "%codeActions.refactor.rewrite.export.title%",
"description": "%codeActions.refactor.rewrite.export.description%"
},
{
"kind": "refactor.move.newFile",
"title": "%codeActions.refactor.move.newFile.title%",
"description": "%codeActions.refactor.move.newFile.description%"
},
{
"kind": "source.organizeImports",
"title": "%codeActions.source.organizeImports.title%"
......
......@@ -84,5 +84,11 @@
"codeActions.refactor.extract.type.description": "Extract type to a type alias.",
"codeActions.refactor.extract.interface.title": "Extract interface",
"codeActions.refactor.extract.interface.description": "Extract type to an interface.",
"codeActions.refactor.rewrite.import.title": "Convert import",
"codeActions.refactor.rewrite.import.description": "Convert between named imports and namespace imports.",
"codeActions.refactor.rewrite.export.title": "Convert export",
"codeActions.refactor.rewrite.export.description": "Convert between default export and named export.",
"codeActions.refactor.move.newFile.title": "Move to a new file",
"codeActions.refactor.move.newFile.description": "Move the expression to a new file.",
"codeActions.source.organizeImports.title": "Organize imports"
}
......@@ -148,11 +148,23 @@ const ExtractInterface = Object.freeze<CodeActionKind>({
matches: refactor => refactor.name.includes('Extract to interface')
});
const Move = Object.freeze<CodeActionKind>({
kind: vscode.CodeActionKind.Refactor.append('move'),
matches: refactor => refactor.name.startsWith('Move')
const MoveNewFile = Object.freeze<CodeActionKind>({
kind: vscode.CodeActionKind.Refactor.append('move').append('newFile'),
matches: refactor => refactor.name.startsWith('Move to a new file')
});
const RewriteImport = Object.freeze<CodeActionKind>({
kind: vscode.CodeActionKind.RefactorRewrite.append('import'),
matches: refactor => refactor.name.startsWith('Convert import')
});
const RewriteExport = Object.freeze<CodeActionKind>({
kind: vscode.CodeActionKind.RefactorRewrite.append('export'),
matches: refactor => refactor.name.startsWith('Convert export')
});
const allKnownCodeActionKinds = [ExtractFunction, ExtractConstant, ExtractType, ExtractInterface, MoveNewFile, RewriteImport, RewriteExport];
class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
public static readonly minVersion = API.v240;
......@@ -194,7 +206,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
const args: Proto.GetApplicableRefactorsRequestArgs = typeConverters.Range.toFileRangeRequestArgs(file, rangeOrSelection);
return this.client.execute('getApplicableRefactors', args, token);
});
if (!response || response.type !== 'response' || !response.body) {
if (response?.type !== 'response' || !response.body) {
return undefined;
}
......@@ -250,7 +262,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
}
private static getKind(refactor: Proto.RefactorActionInfo) {
const match = [ExtractFunction, ExtractConstant, ExtractType, ExtractInterface, Move].find(kind => kind.matches(refactor));
const match = allKnownCodeActionKinds.find(kind => kind.matches(refactor));
return match ? match.kind : vscode.CodeActionKind.Refactor;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册