Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autoFix on save (source.fixAll.csharp) #4717

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/features/fixAllProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down