Skip to content

Commit 62c1243

Browse files
committed
Split up query running, upgrade running, and operations on queries post run.
1 parent 6331092 commit 62c1243

File tree

10 files changed

+403
-331
lines changed

10 files changed

+403
-331
lines changed

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { commands, Event, EventEmitter, ExtensionContext, ProviderResult, TreeDa
44
import * as cli from './cli';
55
import { DatabaseItem, DatabaseManager, getUpgradesDirectories } from "./databases";
66
import { logger } from "./logging";
7-
import { clearCacheInDatabase, upgradeDatabase, UserCancellationException } from "./queries";
7+
import { clearCacheInDatabase, UserCancellationException } from "./run-queries";
88
import * as qsClient from './queryserver-client';
99
import { getOnDiskWorkspaceFolders } from "./helpers";
10+
import { upgradeDatabase } from './upgrades';
1011

1112
type ThemableIconPath = { light: string, dark: string } | string;
1213

extensions/ql-vscode/src/extension.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import * as helpers from './helpers';
1010
import { spawnIdeServer } from './ide-server';
1111
import { InterfaceManager, WebviewReveal } from './interface';
1212
import { ideServerLogger, logger, queryServerLogger } from './logging';
13-
import { compileAndRunQueryAgainstDatabase, EvaluationInfo, tmpDirDisposal, UserCancellationException } from './queries';
14-
import { QueryHistoryItem, QueryHistoryManager } from './query-history';
15-
import * as qsClient from './queryserver-client';
13+
import { compileAndRunQueryAgainstDatabase, tmpDirDisposal, UserCancellationException } from './run-queries';
14+
import { QueryHistoryManager } from './query-history';
1615
import { CodeQLCliServer } from './cli';
1716
import { assertNever } from './helpers-pure';
17+
import * as qsClient from './queryserver-client';
18+
import { CompletedQuery } from './query-results';
1819

1920
/**
2021
* extension.ts
@@ -244,13 +245,13 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
244245
const databaseUI = new DatabaseUI(ctx, cliServer, dbm, qs);
245246
ctx.subscriptions.push(databaseUI);
246247

247-
const qhm = new QueryHistoryManager(ctx, async item => showResultsForInfo(item.info, WebviewReveal.Forced));
248+
const qhm = new QueryHistoryManager(ctx, async item => showResultsForCompletedQuery(item, WebviewReveal.Forced));
248249
const intm = new InterfaceManager(ctx, dbm, cliServer, queryServerLogger);
249250
ctx.subscriptions.push(intm);
250251
archiveFilesystemProvider.activate(ctx);
251252

252-
async function showResultsForInfo(info: EvaluationInfo, forceReveal: WebviewReveal): Promise<void> {
253-
await intm.showResults(info, forceReveal, false);
253+
async function showResultsForCompletedQuery(query: CompletedQuery, forceReveal: WebviewReveal): Promise<void> {
254+
await intm.showResults(query, forceReveal, false);
254255
}
255256

256257
async function compileAndRunQuery(quickEval: boolean, selectedQuery: Uri | undefined) {
@@ -261,8 +262,8 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
261262
throw new Error('Can\'t run query without a selected database');
262263
}
263264
const info = await compileAndRunQueryAgainstDatabase(cliServer, qs, dbItem, quickEval, selectedQuery);
264-
await showResultsForInfo(info, WebviewReveal.NotForced);
265-
qhm.push(new QueryHistoryItem(info));
265+
const item = qhm.addQuery(info);
266+
await showResultsForCompletedQuery(item, WebviewReveal.NotForced);
266267
}
267268
catch (e) {
268269
if (e instanceof UserCancellationException) {

extensions/ql-vscode/src/helpers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22
import { CancellationToken, ProgressOptions, window as Window, workspace } from 'vscode';
33
import { logger } from './logging';
4-
import { EvaluationInfo } from './queries';
4+
import { QueryInfo } from './run-queries';
55

66
export interface ProgressUpdate {
77
/**
@@ -121,16 +121,16 @@ export function getOnDiskWorkspaceFolders() {
121121
* Gets a human-readable name for an evaluated query.
122122
* Uses metadata if it exists, and defaults to the query file name.
123123
*/
124-
export function getQueryName(info: EvaluationInfo) {
124+
export function getQueryName(query: QueryInfo) {
125125
// Queries run through quick evaluation are not usually the entire query file.
126126
// Label them differently and include the line numbers.
127-
if (info.query.quickEvalPosition !== undefined) {
128-
const { line, endLine, fileName } = info.query.quickEvalPosition;
127+
if (query.quickEvalPosition !== undefined) {
128+
const { line, endLine, fileName } = query.quickEvalPosition;
129129
const lineInfo = line === endLine ? `${line}` : `${line}-${endLine}`;
130130
return `Quick evaluation of ${path.basename(fileName)}:${lineInfo}`;
131-
} else if (info.query.metadata && info.query.metadata.name) {
132-
return info.query.metadata.name;
131+
} else if (query.metadata && query.metadata.name) {
132+
return query.metadata.name;
133133
} else {
134-
return path.basename(info.query.program.queryPath);
134+
return path.basename(query.program.queryPath);
135135
}
136136
}

extensions/ql-vscode/src/interface-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Interpretation {
3434

3535
export interface ResultsInfo {
3636
resultsPath: string;
37+
interpretedResultsPath: string;
3738
}
3839

3940
export interface SortedResultSetInfo {

extensions/ql-vscode/src/interface.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { parseSarifLocation, parseSarifPlainTextMessage } from './sarif-utils';
66
import { FivePartLocation, LocationValue, ResolvableLocationValue, WholeFileLocation, tryGetResolvableLocation, LocationStyle } from 'semmle-bqrs';
77
import { DisposableObject } from 'semmle-vscode-utils';
88
import * as vscode from 'vscode';
9-
import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, languages, Location, Position, Range, Uri, window as Window, workspace } from 'vscode';
9+
import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, languages, Location, Range, Uri, window as Window, workspace } from 'vscode';
1010
import { CodeQLCliServer } from './cli';
1111
import { DatabaseItem, DatabaseManager } from './databases';
12-
import * as helpers from './helpers';
1312
import { showAndLogErrorMessage } from './helpers';
1413
import { assertNever } from './helpers-pure';
15-
import { FromResultsViewMsg, Interpretation, IntoResultsViewMsg, ResultsInfo, SortedResultSetInfo, SortedResultsMap, INTERPRETED_RESULTS_PER_RUN_LIMIT, QueryMetadata } from './interface-types';
14+
import { FromResultsViewMsg, Interpretation, IntoResultsViewMsg, SortedResultSetInfo, SortedResultsMap, INTERPRETED_RESULTS_PER_RUN_LIMIT, QueryMetadata } from './interface-types';
1615
import { Logger } from './logging';
1716
import * as messages from './messages';
18-
import { EvaluationInfo, interpretResults, QueryInfo, tmpDir } from './queries';
17+
import { tmpDir, QueryInfo } from './run-queries';
18+
import { CompletedQuery, interpretResults } from './query-results';
1919

2020
/**
2121
* interface.ts
@@ -87,7 +87,7 @@ export function webviewUriToFileUri(webviewUri: string): Uri {
8787
}
8888

8989
export class InterfaceManager extends DisposableObject {
90-
private _displayedEvaluationInfo?: EvaluationInfo;
90+
private _displayedQuery?: CompletedQuery;
9191
private _panel: vscode.WebviewPanel | undefined;
9292
private _panelLoaded = false;
9393
private _panelLoadedCallBacks: (() => void)[] = [];
@@ -180,14 +180,14 @@ export class InterfaceManager extends DisposableObject {
180180
this._panelLoadedCallBacks = [];
181181
break;
182182
case 'changeSort': {
183-
if (this._displayedEvaluationInfo === undefined) {
183+
if (this._displayedQuery === undefined) {
184184
showAndLogErrorMessage("Failed to sort results since evaluation info was unknown.");
185185
break;
186186
}
187187
// Notify the webview that it should expect new results.
188188
await this.postMessage({ t: 'resultsUpdating' });
189-
await this._displayedEvaluationInfo.query.updateSortState(this.cliServer, msg.resultSetName, msg.sortState);
190-
await this.showResults(this._displayedEvaluationInfo, WebviewReveal.NotForced, true);
189+
await this._displayedQuery.updateSortState(this.cliServer, msg.resultSetName, msg.sortState);
190+
await this.showResults(this._displayedQuery, WebviewReveal.NotForced, true);
191191
break;
192192
}
193193
default:
@@ -218,18 +218,18 @@ export class InterfaceManager extends DisposableObject {
218218
* UI interaction requesting results, e.g. clicking on a query
219219
* history entry.
220220
*/
221-
public async showResults(info: EvaluationInfo, forceReveal: WebviewReveal, shouldKeepOldResultsWhileRendering: boolean = false): Promise<void> {
222-
if (info.result.resultType !== messages.QueryResultType.SUCCESS) {
221+
public async showResults(results: CompletedQuery, forceReveal: WebviewReveal, shouldKeepOldResultsWhileRendering: boolean = false): Promise<void> {
222+
if (results.result.resultType !== messages.QueryResultType.SUCCESS) {
223223
return;
224224
}
225225

226-
const interpretation = await this.interpretResultsInfo(info.query, info.query.resultsInfo);
226+
const interpretation = await this.interpretResultsInfo(results.query);
227227

228228
const sortedResultsMap: SortedResultsMap = {};
229-
info.query.sortedResultsInfo.forEach((v, k) =>
229+
results.sortedResultsInfo.forEach((v, k) =>
230230
sortedResultsMap[k] = this.convertPathPropertiesToWebviewUris(v));
231231

232-
this._displayedEvaluationInfo = info;
232+
this._displayedQuery = results;
233233

234234
const panel = this.getPanel();
235235
await this.waitForPanelLoaded();
@@ -242,7 +242,7 @@ export class InterfaceManager extends DisposableObject {
242242
// more asynchronous message to not so abruptly interrupt
243243
// user's workflow by immediately revealing the panel.
244244
const showButton = 'View Results';
245-
const queryName = helpers.getQueryName(info);
245+
const queryName = results.queryName;
246246
const resultPromise = vscode.window.showInformationMessage(
247247
`Finished running query ${(queryName.length > 0) ? ` “${queryName}”` : ''}.`,
248248
showButton
@@ -259,11 +259,11 @@ export class InterfaceManager extends DisposableObject {
259259
await this.postMessage({
260260
t: 'setState',
261261
interpretation,
262-
resultsPath: this.convertPathToWebviewUri(info.query.resultsInfo.resultsPath),
262+
resultsPath: this.convertPathToWebviewUri(results.query.resultsInfo.resultsPath),
263263
sortedResultsMap,
264-
database: info.database,
264+
database: results.database,
265265
shouldKeepOldResultsWhileRendering,
266-
metadata: info.query.metadata
266+
metadata: results.query.metadata
267267
});
268268
}
269269

@@ -288,7 +288,7 @@ private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsP
288288
;
289289
}
290290

291-
private async interpretResultsInfo(query: QueryInfo, resultsInfo: ResultsInfo): Promise<Interpretation | undefined> {
291+
private async interpretResultsInfo(query: QueryInfo): Promise<Interpretation | undefined> {
292292
let interpretation: Interpretation | undefined = undefined;
293293
if (query.hasInterpretedResults()
294294
&& query.quickEvalPosition === undefined // never do results interpretation if quickEval
@@ -299,7 +299,7 @@ private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsP
299299
const sourceInfo = sourceArchiveUri === undefined ?
300300
undefined :
301301
{ sourceArchive: sourceArchiveUri.fsPath, sourceLocationPrefix };
302-
interpretation = await this.getTruncatedResults(query.metadata, resultsInfo.resultsPath, sourceInfo, sourceLocationPrefix);
302+
interpretation = await this.getTruncatedResults(query.metadata, query.resultsInfo.resultsPath, sourceInfo, sourceLocationPrefix);
303303
}
304304
catch (e) {
305305
// If interpretation fails, accept the error and continue

0 commit comments

Comments
 (0)