Skip to content

Commit

Permalink
Highlight bug path positions
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Feb 16, 2022
1 parent 468e442 commit bfcb203
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions src/editor/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import {
Location,
Position,
Range,
ThemeColor,
Uri,
languages,
window
} from 'vscode';
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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bfcb203

Please sign in to comment.