Skip to content

Commit d0982f3

Browse files
committed
Defunctionalize updating sort state
This leads to less sharing of codepaths which is a little bad (slightly more repetition and rendundancy) but a lot good (can independently fix the way raw results are redisplayed so as to be actually correct).
1 parent 890821b commit d0982f3

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 27 additions & 13 deletions
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,25 @@ 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
196+
): Promise<void> {
197+
if (this._displayedQuery === undefined) {
198+
showAndLogErrorMessage(
199+
'Failed to sort results since evaluation info was unknown.'
200+
);
201+
return;
202+
}
203+
// Notify the webview that it should expect new results.
204+
await this.postMessage({ t: 'resultsUpdating' });
205+
this._displayedQuery.updateInterpretedSortState(sortState);
206+
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
207+
}
208+
209+
private async changeRawSortState(
210+
server: cli.CodeQLCliServer,
211+
resultSetName: string,
212+
sortState: RawResultsSortState | undefined
195213
): Promise<void> {
196214
if (this._displayedQuery === undefined) {
197215
showAndLogErrorMessage(
@@ -201,7 +219,11 @@ export class InterfaceManager extends DisposableObject {
201219
}
202220
// Notify the webview that it should expect new results.
203221
await this.postMessage({ t: 'resultsUpdating' });
204-
await update(this._displayedQuery);
222+
this._displayedQuery.updateSortState(
223+
server,
224+
resultSetName,
225+
sortState
226+
);
205227
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
206228
}
207229

@@ -235,18 +257,10 @@ export class InterfaceManager extends DisposableObject {
235257
this._panelLoadedCallBacks = [];
236258
break;
237259
case 'changeSort':
238-
await this.changeSortState(query =>
239-
query.updateSortState(
240-
this.cliServer,
241-
msg.resultSetName,
242-
msg.sortState
243-
)
244-
);
260+
await this.changeRawSortState(this.cliServer, msg.resultSetName, msg.sortState);
245261
break;
246262
case 'changeInterpretedSort':
247-
await this.changeSortState(query =>
248-
query.updateInterpretedSortState(this.cliServer, msg.sortState)
249-
);
263+
await this.changeInterpretedSortState(msg.sortState);
250264
break;
251265
case 'changePage':
252266
if (msg.selectedTable === ALERTS_TABLE_NAME) {

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

Lines changed: 1 addition & 1 deletion
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)