Skip to content

Commit

Permalink
Merge pull request #90 from csordasmarton/highlight_bug_path_positions
Browse files Browse the repository at this point in the history
Highlight bug path positions
  • Loading branch information
Discookie authored Feb 16, 2022
2 parents 92772e8 + bfcb203 commit 7f628b8
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 7f628b8

Please sign in to comment.