@@ -10,7 +10,7 @@ import { CodeQLCliServer } from './cli';
1010import { DatabaseItem , DatabaseManager } from './databases' ;
1111import { showAndLogErrorMessage } from './helpers' ;
1212import { assertNever } from './helpers-pure' ;
13- import { FromResultsViewMsg , Interpretation , INTERPRETED_RESULTS_PER_RUN_LIMIT , IntoResultsViewMsg , QueryMetadata , ResultsPaths , SortedResultSetInfo , SortedResultsMap , InterpretedResultsSortState } from './interface-types' ;
13+ import { FromResultsViewMsg , Interpretation , INTERPRETED_RESULTS_PER_RUN_LIMIT , IntoResultsViewMsg , QueryMetadata , ResultsPaths , SortedResultSetInfo , SortedResultsMap , InterpretedResultsSortState , SortDirection } from './interface-types' ;
1414import { Logger } from './logging' ;
1515import * as messages from './messages' ;
1616import { CompletedQuery , interpretResults } from './query-results' ;
@@ -86,19 +86,28 @@ 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 ) ;
89+ function sortInterpretedResults ( results : Sarif . Result [ ] , sortState : InterpretedResultsSortState | undefined ) : void {
90+ function locToString ( locs : Sarif . Location [ ] | undefined ) : string {
91+ if ( locs === undefined ) return '' ;
92+ return JSON . stringify ( locs [ 0 ] ) || '' ;
93+ }
94+
95+ if ( sortState !== undefined ) {
96+ const direction = sortState . sortDirection === SortDirection . asc ? 1 : - 1 ;
97+ switch ( sortState . sortBy ) {
98+ case 'alert-message' :
99+ results . sort ( ( a , b ) =>
100+ a . message . text === undefined ? 0 :
101+ b . message . text === undefined ? 0 :
102+ direction * ( a . message . text ?. localeCompare ( b . message . text ) ) ) ;
103+ break ;
104+ case 'file-position' :
105+ results . sort ( ( a , b ) =>
106+ direction * locToString ( a . locations ) . localeCompare ( locToString ( b . locations ) ) ) ;
107+ break ;
108+ default :
109+ assertNever ( sortState . sortBy ) ;
110+ }
102111 }
103112}
104113
@@ -295,7 +304,7 @@ export class InterfaceManager extends DisposableObject {
295304 } ) ;
296305 }
297306
298- private async getTruncatedResults ( metadata : QueryMetadata | undefined , resultsPaths : ResultsPaths , sourceInfo : cli . SourceInfo | undefined , sourceLocationPrefix : string , sortState : InterpretedResultsSortState ) : Promise < Interpretation > {
307+ private async getTruncatedResults ( metadata : QueryMetadata | undefined , resultsPaths : ResultsPaths , sourceInfo : cli . SourceInfo | undefined , sourceLocationPrefix : string , sortState : InterpretedResultsSortState | undefined ) : Promise < Interpretation > {
299308 const sarif = await interpretResults ( this . cliServer , metadata , resultsPaths . resultsPath , sourceInfo ) ;
300309 // For performance reasons, limit the number of results we try
301310 // to serialize and send to the webview. TODO: possibly also
@@ -317,7 +326,7 @@ export class InterfaceManager extends DisposableObject {
317326 return { sarif, sourceLocationPrefix, numTruncatedResults, sortState } ;
318327 }
319328
320- private async interpretResultsInfo ( query : QueryInfo , sortState : InterpretedResultsSortState ) : Promise < Interpretation | undefined > {
329+ private async interpretResultsInfo ( query : QueryInfo , sortState : InterpretedResultsSortState | undefined ) : Promise < Interpretation | undefined > {
321330 let interpretation : Interpretation | undefined = undefined ;
322331 if ( await query . hasInterpretedResults ( )
323332 && query . quickEvalPosition === undefined // never do results interpretation if quickEval
@@ -351,7 +360,7 @@ export class InterfaceManager extends DisposableObject {
351360 resultsInfo ,
352361 sourceInfo ,
353362 sourceLocationPrefix ,
354- { sortBy : 'file-position' } // sort order doesn't matter for showing diagnostics in parallel
363+ undefined ,
355364 ) ;
356365
357366 try {
0 commit comments