Skip to content

Commit 7f88575

Browse files
authored
Merge pull request #529 from jcreedcmu/jcreed/fix-527
Fix sorting of raw results
2 parents 890821b + 8c55e3e commit 7f88575

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

extensions/ql-vscode/src/interface.ts

+46-15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
RAW_RESULTS_PAGE_SIZE,
3030
INTERPRETED_RESULTS_PAGE_SIZE,
3131
ALERTS_TABLE_NAME,
32+
RawResultsSortState,
3233
} from './interface-types';
3334
import { Logger } from './logging';
3435
import * as messages from './messages';
@@ -190,8 +191,8 @@ export class InterfaceManager extends DisposableObject {
190191
return this._panel;
191192
}
192193

193-
private async changeSortState(
194-
update: (query: CompletedQuery) => Promise<void>
194+
private async changeInterpretedSortState(
195+
sortState: InterpretedResultsSortState | undefined
195196
): Promise<void> {
196197
if (this._displayedQuery === undefined) {
197198
showAndLogErrorMessage(
@@ -201,10 +202,34 @@ export class InterfaceManager extends DisposableObject {
201202
}
202203
// Notify the webview that it should expect new results.
203204
await this.postMessage({ t: 'resultsUpdating' });
204-
await update(this._displayedQuery);
205+
this._displayedQuery.updateInterpretedSortState(sortState);
205206
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
206207
}
207208

209+
private async changeRawSortState(
210+
resultSetName: string,
211+
sortState: RawResultsSortState | undefined
212+
): Promise<void> {
213+
if (this._displayedQuery === undefined) {
214+
showAndLogErrorMessage(
215+
'Failed to sort results since evaluation info was unknown.'
216+
);
217+
return;
218+
}
219+
// Notify the webview that it should expect new results.
220+
await this.postMessage({ t: 'resultsUpdating' });
221+
await this._displayedQuery.updateSortState(
222+
this.cliServer,
223+
resultSetName,
224+
sortState
225+
);
226+
// Sorting resets to first page, as there is arguably no particular
227+
// correlation between the results on the nth page that the user
228+
// was previously viewing and the contents of the nth page in a
229+
// new sorted order.
230+
await this.showPageOfRawResults(resultSetName, 0, true);
231+
}
232+
208233
private async handleMsgFromView(msg: FromResultsViewMsg): Promise<void> {
209234
switch (msg.t) {
210235
case 'viewSourceFile': {
@@ -235,18 +260,10 @@ export class InterfaceManager extends DisposableObject {
235260
this._panelLoadedCallBacks = [];
236261
break;
237262
case 'changeSort':
238-
await this.changeSortState(query =>
239-
query.updateSortState(
240-
this.cliServer,
241-
msg.resultSetName,
242-
msg.sortState
243-
)
244-
);
263+
await this.changeRawSortState(msg.resultSetName, msg.sortState);
245264
break;
246265
case 'changeInterpretedSort':
247-
await this.changeSortState(query =>
248-
query.updateInterpretedSortState(this.cliServer, msg.sortState)
249-
);
266+
await this.changeInterpretedSortState(msg.sortState);
250267
break;
251268
case 'changePage':
252269
if (msg.selectedTable === ALERTS_TABLE_NAME) {
@@ -423,7 +440,8 @@ export class InterfaceManager extends DisposableObject {
423440
*/
424441
public async showPageOfRawResults(
425442
selectedTable: string,
426-
pageNumber: number
443+
pageNumber: number,
444+
sorted = false
427445
): Promise<void> {
428446
const results = this._displayedQuery;
429447
if (results === undefined) {
@@ -445,8 +463,21 @@ export class InterfaceManager extends DisposableObject {
445463
if (schema === undefined)
446464
throw new Error(`Query result set '${selectedTable}' not found.`);
447465

466+
const getResultsPath = () => {
467+
if (sorted) {
468+
const resultsPath = results.sortedResultsInfo.get(selectedTable)?.resultsPath;
469+
if (resultsPath === undefined) {
470+
throw new Error(`Can't find sorted results for table ${selectedTable}`);
471+
}
472+
return resultsPath;
473+
}
474+
else {
475+
return results.query.resultsPaths.resultsPath;
476+
}
477+
};
478+
448479
const chunk = await this.cliServer.bqrsDecode(
449-
results.query.resultsPaths.resultsPath,
480+
getResultsPath(),
450481
schema.name,
451482
{
452483
offset: schema.pagination?.offsets[pageNumber],

extensions/ql-vscode/src/query-results.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class CompletedQuery implements QueryWithResults {
117117
this.sortedResultsInfo.set(resultSetName, sortedResultSetInfo);
118118
}
119119

120-
async updateInterpretedSortState(_server: cli.CodeQLCliServer, sortState: InterpretedResultsSortState | undefined): Promise<void> {
120+
async updateInterpretedSortState(sortState: InterpretedResultsSortState | undefined): Promise<void> {
121121
this.interpretedResultsSortState = sortState;
122122
}
123123
}

0 commit comments

Comments
 (0)