Skip to content

Commit

Permalink
fix: sas log code action should not impact others (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
scnwwu authored Nov 29, 2024
1 parent 4cfbc7c commit 4e9489f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 12 additions & 8 deletions client/src/components/logViewer/DiagnosticCodeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CodeActionKind,
CodeActionProvider,
Command,
Diagnostic,
DiagnosticSeverity,
ProviderResult,
Range,
Expand All @@ -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];
Expand All @@ -23,37 +24,40 @@ 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,
),
];
}

private createCodeAction(
document: TextDocument,
context: CodeActionContext,
diagnostics: Diagnostic[],
command: string,
): CodeAction {
const action = new CodeAction("", CodeActionKind.QuickFix);
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/logViewer/sasDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
});

Expand Down

0 comments on commit 4e9489f

Please sign in to comment.