From bfcb203f244accaf75869384c40bf6ee918118ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Csord=C3=A1s?= Date: Mon, 14 Feb 2022 16:11:36 +0100 Subject: [PATCH] Highlight bug path positions --- package.json | 22 +++++++++++++++++++++- src/editor/diagnostics.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 818ebfb..b629fe0 100644 --- a/package.json +++ b/package.json @@ -198,7 +198,27 @@ "when": "codechecker.sidebar.showReports" } ] - } + }, + "colors": [ + { + "id": "codechecker.highlightBugReportPoints.background", + "description": "Color for highlighting bug report points.", + "defaults": { + "dark": "#00000000", + "light": "#eeb", + "highContrast": "#00000000" + } + }, + { + "id": "codechecker.highlightBugReportPoints.border", + "description": "Border color for highlighting bug report points.", + "defaults": { + "dark": "#eeb", + "light": "#e07a16", + "highContrast": "#eeb" + } + } + ] }, "scripts": { "vscode:prepublish": "yarn run package", diff --git a/src/editor/diagnostics.ts b/src/editor/diagnostics.ts index d054442..740cb0f 100644 --- a/src/editor/diagnostics.ts +++ b/src/editor/diagnostics.ts @@ -7,6 +7,7 @@ import { Location, Position, Range, + ThemeColor, Uri, languages, window @@ -14,6 +15,15 @@ import { import { ExtensionApi } from '../backend/api'; import { DiagnosticReport } from '../backend/types'; +// Decoration type for highlighting report step positions. +const reportStepDecorationType = window.createTextEditorDecorationType({ + backgroundColor: new ThemeColor('codechecker.highlightBugReportPoints.background'), + borderColor: new ThemeColor('codechecker.highlightBugReportPoints.border'), + borderWidth: '1px', + borderStyle: 'solid', + borderRadius: '2px', +}); + // TODO: implement api // Get diagnostics severity for the given CodeChecker severity. @@ -74,6 +84,34 @@ export class DiagnosticRenderer { } this.updateAllDiagnostics(); + this.highlightActiveBugStep(); + } + + highlightActiveBugStep() { + const editor = window.activeTextEditor; + if (!editor) { + return; + } + + const diagnostic = ExtensionApi.diagnostics.selectedEntry?.diagnostic; + if (!diagnostic) { + // Hide report step decorations when no report step is selected. + editor.setDecorations(reportStepDecorationType, []); + return; + } + + // Decorate report steps. + const ranges = diagnostic.bug_path_positions.reduce((prev: Range[], curr) => { + if (curr.file.original_path === editor.document.uri.fsPath) { + const range = curr.range; + prev.push(new Range( + new Position(range.start_line - 1, range.start_col - 1), + new Position(range.end_line - 1, range.end_col) + )); + } + return prev; + }, []); + editor.setDecorations(reportStepDecorationType, ranges); } // TODO: Implement CancellableToken