diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index 653ed81605780d9415f32d6006a13c94454ab906..84dd4a284cdce4b30fa973d811723c2eeca3afb2 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -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%" diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index db6e1366c15fd49a8d9a74c3c5650fb3795e4c7b..52d7a05fa15e8b4a659e8d20d63b84268b75b0c1 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -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" } diff --git a/extensions/typescript-language-features/src/features/refactor.ts b/extensions/typescript-language-features/src/features/refactor.ts index 1015691f73195927014ee814a56c2c832dd3d173..f7f295603b935c60c4abb89a5f9de8e30c1d57c8 100644 --- a/extensions/typescript-language-features/src/features/refactor.ts +++ b/extensions/typescript-language-features/src/features/refactor.ts @@ -148,11 +148,23 @@ const ExtractInterface = Object.freeze({ matches: refactor => refactor.name.includes('Extract to interface') }); -const Move = Object.freeze({ - kind: vscode.CodeActionKind.Refactor.append('move'), - matches: refactor => refactor.name.startsWith('Move') +const MoveNewFile = Object.freeze({ + kind: vscode.CodeActionKind.Refactor.append('move').append('newFile'), + matches: refactor => refactor.name.startsWith('Move to a new file') }); +const RewriteImport = Object.freeze({ + kind: vscode.CodeActionKind.RefactorRewrite.append('import'), + matches: refactor => refactor.name.startsWith('Convert import') +}); + +const RewriteExport = Object.freeze({ + 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; }