mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
Fix #37288
This commit is contained in:
@@ -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<boolean> {
|
||||
return applyCodeActionCommands(this.client, actions);
|
||||
}
|
||||
}
|
||||
|
||||
export default class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
private _supportedCodeActions?: Thenable<NumberSet>;
|
||||
|
||||
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: []
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user