Skip to content

Commit cc9849e

Browse files
committed
Switch back to computing the file names in one place.
1 parent 78e3612 commit cc9849e

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export interface Interpretation {
3737
sarif: sarif.Log;
3838
}
3939

40-
export interface ResultsInfo {
40+
export interface ResultsPaths {
4141
resultsPath: string;
42+
interpretedResultsPath: string;
4243
}
4344

4445
export interface SortedResultSetInfo {
@@ -60,6 +61,7 @@ export interface ResultsUpdatingMsg {
6061
export interface SetStateMsg {
6162
t: 'setState';
6263
resultsPath: string;
64+
origResultsPaths: ResultsPaths;
6365
sortedResultsMap: SortedResultsMap;
6466
interpretation: undefined | Interpretation;
6567
database: DatabaseInfo;
@@ -94,7 +96,7 @@ interface ToggleDiagnostics {
9496
t: 'toggleDiagnostics';
9597
databaseUri: string;
9698
metadata?: QueryMetadata
97-
resultsPath: string;
99+
origResultsPaths: ResultsPaths;
98100
visible: boolean;
99101
kind?: string;
100102
};

extensions/ql-vscode/src/interface.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ 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';
1212
import * as helpers from './helpers';
1313
import { showAndLogErrorMessage } from './helpers';
1414
import { assertNever } from './helpers-pure';
15-
import { FromResultsViewMsg, Interpretation, IntoResultsViewMsg, ResultsInfo, SortedResultSetInfo, SortedResultsMap, INTERPRETED_RESULTS_PER_RUN_LIMIT, QueryMetadata } from './interface-types';
15+
import { FromResultsViewMsg, Interpretation, IntoResultsViewMsg, ResultsPaths, SortedResultSetInfo, SortedResultsMap, INTERPRETED_RESULTS_PER_RUN_LIMIT, QueryMetadata } from './interface-types';
1616
import { Logger } from './logging';
1717
import * as messages from './messages';
1818
import { EvaluationInfo, interpretResults, QueryInfo, tmpDir } from './queries';
@@ -166,7 +166,7 @@ export class InterfaceManager extends DisposableObject {
166166
if (msg.visible) {
167167
const databaseItem = this.databaseManager.findDatabaseItem(Uri.parse(msg.databaseUri));
168168
if (databaseItem !== undefined) {
169-
await this.showResultsAsDiagnostics(msg.resultsPath, msg.metadata, databaseItem);
169+
await this.showResultsAsDiagnostics(msg.origResultsPaths, msg.metadata, databaseItem);
170170
}
171171
} else {
172172
// TODO: Only clear diagnostics on the same database.
@@ -223,7 +223,7 @@ export class InterfaceManager extends DisposableObject {
223223
return;
224224
}
225225

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

228228
const sortedResultsMap: SortedResultsMap = {};
229229
info.query.sortedResultsInfo.forEach((v, k) =>
@@ -259,16 +259,17 @@ export class InterfaceManager extends DisposableObject {
259259
await this.postMessage({
260260
t: 'setState',
261261
interpretation,
262-
resultsPath: this.convertPathToWebviewUri(info.query.resultsInfo.resultsPath),
262+
origResultsPaths: info.query.resultsPaths,
263+
resultsPath: this.convertPathToWebviewUri(info.query.resultsPaths.resultsPath),
263264
sortedResultsMap,
264265
database: info.database,
265266
shouldKeepOldResultsWhileRendering,
266267
metadata: info.query.metadata
267268
});
268269
}
269270

270-
private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsPathOnDisk: string, sourceInfo : cli.SourceInfo | undefined, sourceLocationPrefix : string ) : Promise<Interpretation> {
271-
const sarif = await interpretResults(this.cliServer, metadata, resultsPathOnDisk, sourceInfo);
271+
private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsInfo: ResultsPaths, sourceInfo : cli.SourceInfo | undefined, sourceLocationPrefix : string ) : Promise<Interpretation> {
272+
const sarif = await interpretResults(this.cliServer, metadata, resultsInfo, sourceInfo);
272273
// For performance reasons, limit the number of results we try
273274
// to serialize and send to the webview. TODO: possibly also
274275
// limit number of paths per result, number of steps per path,
@@ -288,7 +289,7 @@ private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsP
288289
;
289290
}
290291

291-
private async interpretResultsInfo(query: QueryInfo, resultsInfo: ResultsInfo): Promise<Interpretation | undefined> {
292+
private async interpretResultsInfo(query: QueryInfo, resultsInfo: ResultsPaths): Promise<Interpretation | undefined> {
292293
let interpretation: Interpretation | undefined = undefined;
293294
if (query.hasInterpretedResults()
294295
&& query.quickEvalPosition === undefined // never do results interpretation if quickEval
@@ -299,7 +300,7 @@ private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsP
299300
const sourceInfo = sourceArchiveUri === undefined ?
300301
undefined :
301302
{ sourceArchive: sourceArchiveUri.fsPath, sourceLocationPrefix };
302-
interpretation = await this.getTruncatedResults(query.metadata, resultsInfo.resultsPath, sourceInfo, sourceLocationPrefix);
303+
interpretation = await this.getTruncatedResults(query.metadata, resultsInfo, sourceInfo, sourceLocationPrefix);
303304
}
304305
catch (e) {
305306
// If interpretation fails, accept the error and continue
@@ -311,15 +312,13 @@ private async getTruncatedResults(metadata : QueryMetadata | undefined ,resultsP
311312
}
312313

313314

314-
private async showResultsAsDiagnostics(webviewResultsUri: string, metadata: QueryMetadata | undefined, database: DatabaseItem) {
315-
// URIs from the webview have the vscode-resource scheme, so convert into a filesystem URI first.
316-
const resultsPathOnDisk = webviewUriToFileUri(webviewResultsUri).fsPath;
315+
private async showResultsAsDiagnostics(resultsInfo: ResultsPaths, metadata: QueryMetadata | undefined, database: DatabaseItem) {
317316
const sourceLocationPrefix = await database.getSourceLocationPrefix(this.cliServer);
318317
const sourceArchiveUri = database.sourceArchive;
319318
const sourceInfo = sourceArchiveUri === undefined ?
320319
undefined :
321320
{ sourceArchive: sourceArchiveUri.fsPath, sourceLocationPrefix };
322-
const interpretation = await this.getTruncatedResults(metadata, resultsPathOnDisk, sourceInfo, sourceLocationPrefix);
321+
const interpretation = await this.getTruncatedResults(metadata, resultsInfo, sourceInfo, sourceLocationPrefix);
323322

324323
try {
325324
await this.showProblemResultsAsDiagnostics(interpretation, database);

extensions/ql-vscode/src/queries.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77
import * as cli from './cli';
88
import { DatabaseItem, getUpgradesDirectories } from './databases';
99
import * as helpers from './helpers';
10-
import { DatabaseInfo, SortState, ResultsInfo, SortedResultSetInfo, QueryMetadata } from './interface-types';
10+
import { DatabaseInfo, SortState, ResultsPaths, SortedResultSetInfo, QueryMetadata } from './interface-types';
1111
import { logger } from './logging';
1212
import * as messages from './messages';
1313
import * as qsClient from './queryserver-client';
@@ -41,7 +41,7 @@ export class UserCancellationException extends Error { }
4141
*/
4242
export class QueryInfo {
4343
compiledQueryPath: string;
44-
resultsInfo: ResultsInfo;
44+
resultsPaths: ResultsPaths;
4545
private static nextQueryId = 0;
4646

4747
/**
@@ -59,7 +59,8 @@ export class QueryInfo {
5959
) {
6060
this.queryId = QueryInfo.nextQueryId++;
6161
this.compiledQueryPath = path.join(tmpDir.name, `compiledQuery${this.queryId}.qlo`);
62-
this.resultsInfo = {
62+
this.resultsPaths = {
63+
interpretedResultsPath: path.join(tmpDir.name, `interpretedResults${this.queryId}.sarif`),
6364
resultsPath: path.join(tmpDir.name, `results${this.queryId}.bqrs`),
6465
};
6566
this.sortedResultsInfo = new Map();
@@ -77,7 +78,7 @@ export class QueryInfo {
7778
const callbackId = qs.registerCallback(res => { result = res });
7879

7980
const queryToRun: messages.QueryToRun = {
80-
resultsPath: this.resultsInfo.resultsPath,
81+
resultsPath: this.resultsPaths.resultsPath,
8182
qlo: vscode.Uri.file(this.compiledQueryPath).toString(),
8283
allowUnknownTemplates: true,
8384
id: callbackId,
@@ -164,19 +165,18 @@ export class QueryInfo {
164165
sortState
165166
};
166167

167-
await server.sortBqrs(this.resultsInfo.resultsPath, sortedResultSetInfo.resultsPath, resultSetName, [sortState.columnIndex], [sortState.direction]);
168+
await server.sortBqrs(this.resultsPaths.resultsPath, sortedResultSetInfo.resultsPath, resultSetName, [sortState.columnIndex], [sortState.direction]);
168169
this.sortedResultsInfo.set(resultSetName, sortedResultSetInfo);
169170
}
170171
}
171172

172173
/**
173174
* Call cli command to interpret results.
174175
*/
175-
export async function interpretResults(server: cli.CodeQLCliServer, metadata: QueryMetadata | undefined, resultsPath: string, sourceInfo?: cli.SourceInfo): Promise<sarif.Log> {
176-
const interpretedResultsPath = resultsPath + ".interpreted.sarif"
176+
export async function interpretResults(server: cli.CodeQLCliServer, metadata: QueryMetadata | undefined, resultsInfo: ResultsPaths, sourceInfo?: cli.SourceInfo): Promise<sarif.Log> {
177177

178-
if (await fs.pathExists(interpretedResultsPath)) {
179-
return JSON.parse(await fs.readFile(interpretedResultsPath, 'utf8'));
178+
if (await fs.pathExists(resultsInfo.interpretedResultsPath)) {
179+
return JSON.parse(await fs.readFile(resultsInfo.interpretedResultsPath, 'utf8'));
180180
}
181181
if (metadata == undefined) {
182182
throw new Error('Can\'t interpret results without query metadata');
@@ -190,7 +190,7 @@ export async function interpretResults(server: cli.CodeQLCliServer, metadata: Qu
190190
// SARIF format does, so in the absence of one, we use a dummy id.
191191
id = "dummy-id";
192192
}
193-
return await server.interpretBqrs( { kind, id }, resultsPath, interpretedResultsPath, sourceInfo);
193+
return await server.interpretBqrs( { kind, id }, resultsInfo.resultsPath, resultsInfo.interpretedResultsPath, sourceInfo);
194194
}
195195

196196
export interface EvaluationInfo {

extensions/ql-vscode/src/view/result-tables.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { DatabaseInfo, Interpretation, SortState, QueryMetadata } from '../interface-types';
2+
import { DatabaseInfo, Interpretation, SortState, QueryMetadata, ResultsPaths } from '../interface-types';
33
import { PathTable } from './alert-table';
44
import { RawTable } from './raw-results-table';
55
import { ResultTableProps, tableSelectionHeaderClassName, toggleDiagnosticsClassName } from './result-table-utils';
@@ -13,7 +13,8 @@ export interface ResultTablesProps {
1313
interpretation: Interpretation | undefined;
1414
database: DatabaseInfo;
1515
metadata? : QueryMetadata
16-
resultsPath: string | undefined;
16+
resultsPath: string ;
17+
origResultsPaths: ResultsPaths;
1718
sortStates: Map<string, SortState>;
1819
isLoadingNewResults: boolean;
1920
}
@@ -77,7 +78,7 @@ export class ResultTables
7778
render(): React.ReactNode {
7879
const { selectedTable } = this.state;
7980
const resultSets = this.getResultSets();
80-
const { database, resultsPath, metadata } = this.props;
81+
const { database, resultsPath, metadata, origResultsPaths } = this.props;
8182

8283
// Only show the Problems view display checkbox for the alerts table.
8384
const diagnosticsCheckBox = selectedTable === ALERTS_TABLE_NAME ?
@@ -86,7 +87,7 @@ export class ResultTables
8687
if (resultsPath !== undefined) {
8788
vscode.postMessage({
8889
t: 'toggleDiagnostics',
89-
resultsPath: resultsPath,
90+
origResultsPaths: origResultsPaths,
9091
databaseUri: database.databaseUri,
9192
visible: e.target.checked,
9293
metadata: metadata

extensions/ql-vscode/src/view/results.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Rdom from 'react-dom';
33
import * as bqrs from 'semmle-bqrs';
44
import { ElementBase, LocationValue, PrimitiveColumnValue, PrimitiveTypeKind, ResultSetSchema, tryGetResolvableLocation } from 'semmle-bqrs';
55
import { assertNever } from '../helpers-pure';
6-
import { DatabaseInfo, FromResultsViewMsg, Interpretation, IntoResultsViewMsg, SortedResultSetInfo, SortState, NavigatePathMsg, QueryMetadata } from '../interface-types';
6+
import { DatabaseInfo, FromResultsViewMsg, Interpretation, IntoResultsViewMsg, SortedResultSetInfo, SortState, NavigatePathMsg, QueryMetadata, ResultsPaths } from '../interface-types';
77
import { ResultTables } from './result-tables';
88
import { EventHandlers as EventHandlerList } from './event-handler-list';
99

@@ -127,6 +127,7 @@ async function parseResultSets(response: Response): Promise<readonly ResultSet[]
127127

128128
interface ResultsInfo {
129129
resultsPath: string;
130+
origResultsPaths: ResultsPaths;
130131
database: DatabaseInfo;
131132
interpretation: Interpretation | undefined;
132133
sortedResultsMap: Map<string, SortedResultSetInfo>;
@@ -186,6 +187,7 @@ class App extends React.Component<{}, ResultsViewState> {
186187
case 'setState':
187188
this.updateStateWithNewResultsInfo({
188189
resultsPath: msg.resultsPath,
190+
origResultsPaths: msg.origResultsPaths,
189191
sortedResultsMap: new Map(Object.entries(msg.sortedResultsMap)),
190192
database: msg.database,
191193
interpretation: msg.interpretation,
@@ -304,11 +306,12 @@ class App extends React.Component<{}, ResultsViewState> {
304306

305307
render() {
306308
const displayedResults = this.state.displayedResults;
307-
if (displayedResults.results !== null) {
309+
if (displayedResults.results !== null && displayedResults.resultsInfo !== null) {
308310
return <ResultTables rawResultSets={displayedResults.results.resultSets}
309311
interpretation={displayedResults.resultsInfo ? displayedResults.resultsInfo.interpretation : undefined}
310312
database={displayedResults.results.database}
311-
resultsPath={displayedResults.resultsInfo ? displayedResults.resultsInfo.resultsPath : undefined}
313+
origResultsPaths={displayedResults.resultsInfo.origResultsPaths}
314+
resultsPath={displayedResults.resultsInfo.resultsPath}
312315
metadata={displayedResults.resultsInfo ? displayedResults.resultsInfo.metadata : undefined}
313316
sortStates={displayedResults.results.sortStates}
314317
isLoadingNewResults={this.state.isExpectingResultsUpdate || this.state.nextResultsInfo !== null} />;

0 commit comments

Comments
 (0)