mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Simplify getFixAllActions
This commit is contained in:
@@ -186,13 +186,11 @@ class SourceAddMissingImports extends SourceAction {
|
||||
|
||||
class TypeScriptAutoFixProvider implements vscode.CodeActionProvider {
|
||||
|
||||
public static readonly metadata: vscode.CodeActionProviderMetadata = {
|
||||
providedCodeActionKinds: [
|
||||
SourceFixAll.kind,
|
||||
SourceRemoveUnused.kind,
|
||||
SourceAddMissingImports.kind,
|
||||
]
|
||||
};
|
||||
private static kindProviders = [
|
||||
SourceFixAll,
|
||||
SourceRemoveUnused,
|
||||
SourceAddMissingImports,
|
||||
];
|
||||
|
||||
constructor(
|
||||
private readonly client: ITypeScriptServiceClient,
|
||||
@@ -200,6 +198,12 @@ class TypeScriptAutoFixProvider implements vscode.CodeActionProvider {
|
||||
private readonly diagnosticsManager: DiagnosticsManager,
|
||||
) { }
|
||||
|
||||
public get metadata(): vscode.CodeActionProviderMetadata {
|
||||
return {
|
||||
providedCodeActionKinds: TypeScriptAutoFixProvider.kindProviders.map(x => x.kind),
|
||||
};
|
||||
}
|
||||
|
||||
public async provideCodeActions(
|
||||
document: vscode.TextDocument,
|
||||
_range: vscode.Range,
|
||||
@@ -238,21 +242,9 @@ class TypeScriptAutoFixProvider implements vscode.CodeActionProvider {
|
||||
}
|
||||
|
||||
private getFixAllActions(only: vscode.CodeActionKind): SourceAction[] {
|
||||
const fixes = [];
|
||||
|
||||
if (only.intersects(SourceFixAll.kind)) {
|
||||
fixes.push(new SourceFixAll());
|
||||
}
|
||||
|
||||
if (only.intersects(SourceRemoveUnused.kind)) {
|
||||
fixes.push(new SourceRemoveUnused());
|
||||
}
|
||||
|
||||
if (only.intersects(SourceAddMissingImports.kind)) {
|
||||
fixes.push(new SourceAddMissingImports());
|
||||
}
|
||||
|
||||
return fixes;
|
||||
return TypeScriptAutoFixProvider.kindProviders
|
||||
.filter(provider => only.intersects(provider.kind))
|
||||
.map(provider => new provider());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,8 +254,8 @@ export function register(
|
||||
fileConfigurationManager: FileConfigurationManager,
|
||||
diagnosticsManager: DiagnosticsManager,
|
||||
) {
|
||||
return new VersionDependentRegistration(client, API.v300, () =>
|
||||
vscode.languages.registerCodeActionsProvider(selector,
|
||||
new TypeScriptAutoFixProvider(client, fileConfigurationManager, diagnosticsManager),
|
||||
TypeScriptAutoFixProvider.metadata));
|
||||
return new VersionDependentRegistration(client, API.v300, () => {
|
||||
const provider = new TypeScriptAutoFixProvider(client, fileConfigurationManager, diagnosticsManager);
|
||||
return vscode.languages.registerCodeActionsProvider(selector, provider, provider.metadata);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user