From 0ab876da7345bc3379336e823f8a8e0991f8a7cd Mon Sep 17 00:00:00 2001 From: Alex Gentile Date: Sat, 21 Aug 2021 13:57:38 -0700 Subject: [PATCH] Fix autoFix on save (source.fixAll.csharp) --- src/features/fixAllProvider.ts | 9 ++++++++- src/omnisharp/extension.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/features/fixAllProvider.ts b/src/features/fixAllProvider.ts index 1299755b0..aa010c02c 100644 --- a/src/features/fixAllProvider.ts +++ b/src/features/fixAllProvider.ts @@ -15,6 +15,13 @@ import { buildEditForResponse } from '../omnisharp/fileOperationsResponseEditBui import { CancellationToken } from 'vscode-languageserver-protocol'; export class FixAllProvider extends AbstractProvider implements vscode.CodeActionProvider { + public static fixAllCodeActionKind = + vscode.CodeActionKind.SourceFixAll.append('csharp'); + + public static metadata: vscode.CodeActionProviderMetadata = { + providedCodeActionKinds: [FixAllProvider.fixAllCodeActionKind] + }; + public constructor(private server: OmniSharpServer, languageMiddlewareFeature: LanguageMiddlewareFeature) { super(server, languageMiddlewareFeature); let disposable = new CompositeDisposable(); @@ -35,7 +42,7 @@ export class FixAllProvider extends AbstractProvider implements vscode.CodeActio return []; } - if (context.only.value === "source.fixAll.csharp") { + if (context.only.contains(FixAllProvider.fixAllCodeActionKind)) { await this.applyFixes(document.fileName, FixAllScope.Document, undefined); } diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index 86a7d34ee..a50f1abae 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -103,7 +103,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an // so that it will be cleaned up if OmniSharp is restarted. const fixAllProvider = new FixAllProvider(server, languageMiddlewareFeature); localDisposables.add(fixAllProvider); - localDisposables.add(vscode.languages.registerCodeActionsProvider(documentSelector, fixAllProvider)); + localDisposables.add(vscode.languages.registerCodeActionsProvider(documentSelector, fixAllProvider, FixAllProvider.metadata)); localDisposables.add(reportDiagnostics(server, advisor, languageMiddlewareFeature)); localDisposables.add(forwardChanges(server)); localDisposables.add(trackVirtualDocuments(server, eventStream));