From 4e9489f5225df28262d8fcb4b1f10c3c2c22fa6b Mon Sep 17 00:00:00 2001 From: Wei Wu <96556502+scnwwu@users.noreply.github.com> Date: Fri, 29 Nov 2024 03:19:55 -0500 Subject: [PATCH] fix: sas log code action should not impact others (#1308) --- .../logViewer/DiagnosticCodeActionProvider.ts | 20 +++++++++++-------- .../components/logViewer/sasDiagnostics.ts | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/src/components/logViewer/DiagnosticCodeActionProvider.ts b/client/src/components/logViewer/DiagnosticCodeActionProvider.ts index dc34403d0..d6dfab70b 100644 --- a/client/src/components/logViewer/DiagnosticCodeActionProvider.ts +++ b/client/src/components/logViewer/DiagnosticCodeActionProvider.ts @@ -6,6 +6,7 @@ import { CodeActionKind, CodeActionProvider, Command, + Diagnostic, DiagnosticSeverity, ProviderResult, Range, @@ -14,7 +15,7 @@ import { l10n, } from "vscode"; -import { sasDiagnostic } from "./sasDiagnostics"; +import { diagnosticSource, sasDiagnostic } from "./sasDiagnostics"; export class DiagnosticCodeActionProvider implements CodeActionProvider { public static readonly providedCodeActionKinds = [CodeActionKind.QuickFix]; @@ -23,29 +24,32 @@ export class DiagnosticCodeActionProvider implements CodeActionProvider { _range: Range | Selection, context: CodeActionContext, ): ProviderResult<(CodeAction | Command)[]> { - if (context.diagnostics.length === 0) { + const diagnostics = context.diagnostics.filter( + (diagnostic) => diagnostic.source === diagnosticSource, + ); + if (diagnostics.length === 0) { return []; } return [ this.createCodeAction( document, - context, + diagnostics, sasDiagnostic.DiagnosticCommands.IgnoreCommand, ), this.createCodeAction( document, - context, + diagnostics, sasDiagnostic.DiagnosticCommands.IgnoreAllWarningCommand, ), this.createCodeAction( document, - context, + diagnostics, sasDiagnostic.DiagnosticCommands.IgnoreAllErrorCommand, ), this.createCodeAction( document, - context, + diagnostics, sasDiagnostic.DiagnosticCommands.IgnoreAllCommand, ), ]; @@ -53,7 +57,7 @@ export class DiagnosticCodeActionProvider implements CodeActionProvider { private createCodeAction( document: TextDocument, - context: CodeActionContext, + diagnostics: Diagnostic[], command: string, ): CodeAction { const action = new CodeAction("", CodeActionKind.QuickFix); @@ -64,7 +68,7 @@ export class DiagnosticCodeActionProvider implements CodeActionProvider { action.command = { command: command, title: l10n.t("Ignore: current position"), - arguments: [context.diagnostics, document.uri], + arguments: [diagnostics, document.uri], }; break; case sasDiagnostic.DiagnosticCommands.IgnoreAllWarningCommand: diff --git a/client/src/components/logViewer/sasDiagnostics.ts b/client/src/components/logViewer/sasDiagnostics.ts index 19da3f5b4..b2ea7c573 100644 --- a/client/src/components/logViewer/sasDiagnostics.ts +++ b/client/src/components/logViewer/sasDiagnostics.ts @@ -22,6 +22,8 @@ import { DiagnosticCodeActionProvider } from "./DiagnosticCodeActionProvider"; import { Problem } from "./ProblemProcessor"; import { parseLog } from "./logParser"; +export const diagnosticSource = "sas log"; + let diagnosticCollection: DiagnosticCollection; enum DiagnosticCommands { @@ -120,7 +122,7 @@ function constructDiagnostics(problems: Problem[]): Diagnostic[] { message, type === "error" ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, ); - diagnostic.source = "sas log"; + diagnostic.source = diagnosticSource; return diagnostic; });