Skip to content

Commit 68f14d1

Browse files
committed
Sort alerts according to UI-chosen sort order
1 parent d325463 commit 68f14d1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ export function webviewUriToFileUri(webviewUri: string): Uri {
8686
return Uri.file(path);
8787
}
8888

89+
function sortInterpretedResults(results: Sarif.Result[], sortState: InterpretedResultsSortState): void {
90+
switch (sortState.sortBy) {
91+
case 'alert-message':
92+
results.sort((a, b) =>
93+
a.message.text === undefined ? 0 :
94+
b.message.text === undefined ? 0 :
95+
a.message.text?.localeCompare(b.message.text));
96+
break;
97+
case 'file-position':
98+
// default to the order found in the sarif file
99+
break;
100+
default:
101+
assertNever(sortState.sortBy);
102+
}
103+
}
104+
89105
export class InterfaceManager extends DisposableObject {
90106
private _displayedQuery?: CompletedQuery;
91107
private _panel: vscode.WebviewPanel | undefined;
@@ -287,9 +303,11 @@ export class InterfaceManager extends DisposableObject {
287303
// or throw an error if we are in aggregate trying to send
288304
// massively too much data, as it can make the extension
289305
// unresponsive.
306+
290307
let numTruncatedResults = 0;
291308
sarif.runs.forEach(run => {
292309
if (run.results !== undefined) {
310+
sortInterpretedResults(run.results, sortState);
293311
if (run.results.length > INTERPRETED_RESULTS_PER_RUN_LIMIT) {
294312
numTruncatedResults += run.results.length - INTERPRETED_RESULTS_PER_RUN_LIMIT;
295313
run.results = run.results.slice(0, INTERPRETED_RESULTS_PER_RUN_LIMIT);

0 commit comments

Comments
 (0)