diff --git a/extensions/typescript/src/features/quickFixProvider.ts b/extensions/typescript/src/features/quickFixProvider.ts index 5a8c74f6b2f..9293818f1b0 100644 --- a/extensions/typescript/src/features/quickFixProvider.ts +++ b/extensions/typescript/src/features/quickFixProvider.ts @@ -9,19 +9,38 @@ import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import { vsRangeToTsFileRange } from '../utils/convert'; import FormattingConfigurationManager from './formattingConfigurationManager'; -import { getEditForCodeAction } from '../utils/codeAction'; +import { getEditForCodeAction, applyCodeActionCommands } from '../utils/codeAction'; +import { Command, CommandManager } from '../utils/commandManager'; interface NumberSet { [key: number]: boolean; } +class ApplyCodeActionCommand implements Command { + public static readonly ID = '_typescript.applyCodeActionCommand'; + public readonly id = ApplyCodeActionCommand.ID; + + constructor( + private readonly client: ITypeScriptServiceClient + ) { } + + public async execute( + actions: Proto.CodeAction + ): Promise { + return applyCodeActionCommands(this.client, actions); + } +} + export default class TypeScriptQuickFixProvider implements vscode.CodeActionProvider { private _supportedCodeActions?: Thenable; constructor( private readonly client: ITypeScriptServiceClient, - private readonly formattingConfigurationManager: FormattingConfigurationManager - ) { } + private readonly formattingConfigurationManager: FormattingConfigurationManager, + commandManager: CommandManager + ) { + commandManager.register(new ApplyCodeActionCommand(client)); + } public provideCodeActions( _document: vscode.TextDocument, @@ -88,6 +107,11 @@ export default class TypeScriptQuickFixProvider implements vscode.CodeActionProv return { title: action.description, edits: getEditForCodeAction(this.client, action), + command: action.commands ? { + command: ApplyCodeActionCommand.ID, + arguments: [action], + title: action.description + } : undefined, diagnostics: [] }; } diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index 9e4a63cdbdf..82dd3b9326d 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -144,7 +144,7 @@ class LanguageProvider { this.disposables.push(languages.registerDocumentSymbolProvider(selector, new (await import('./features/documentSymbolProvider')).default(client))); this.disposables.push(languages.registerSignatureHelpProvider(selector, new (await import('./features/signatureHelpProvider')).default(client), '(', ',')); this.disposables.push(languages.registerRenameProvider(selector, new (await import('./features/renameProvider')).default(client))); - this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/quickFixProvider')).default(client, this.formattingOptionsManager))); + this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/quickFixProvider')).default(client, this.formattingOptionsManager, commandManager))); this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/refactorProvider')).default(client, this.formattingOptionsManager, commandManager))); this.registerVersionDependentProviders();