Skip to content

Commit c5ceb22

Browse files
committed
Add query items immediately
This is a large commit and includes all the changes to add query history items immediately. This also includes some smaller related changes that were hit while cleaning this area up. The major part of this change is a refactoring of what we store in the query history list. Previously, the `CompletedQuery` was stored. Previously, objects of this type include all information about a query that was run including: - Its source file and text range (if a quick eval) - Its database - Its label - The query results itself - Metrics about the query run - Metadata about the query itself Now, the item stored is called a `FullQueryInfo`, which has two properties: - InitialQueryInfo: all the data about the query that we know _before_ the query completes, eg- its source file and text range, database, and label - CompletedQueryInfo: all the data about the query that we can only learn _after_ the query completes. This is an optional property. There is also a `failureReason` property, which is an optional string describing why the query failed. There is also a `FullCompletedQueryInfo` type, which only exists to help with stronger typing. It is a `FullQueryInfo` with a non-optional `CompletedQueryInfo`. Most of the changes are around changing how the query history accesses its history list. There are some other smaller changes included here: - New icon for completed query (previously, completed queries had no icons). - New spinning icon for in progress queries. - Better error handling in the logger to handle log messages when the extension is shutting down. This mostly helps clean up the output during tests. - Add more disposables to subscriptions to be disposed of when the extension shuts down.
1 parent 894eb70 commit c5ceb22

15 files changed

Lines changed: 1021 additions & 683 deletions

File tree

Lines changed: 7 additions & 0 deletions
Loading

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import * as path from 'path';
1010

1111
import { tmpDir } from '../run-queries';
12-
import { CompletedQuery } from '../query-results';
1312
import {
1413
FromCompareViewMessage,
1514
ToCompareViewMessage,
@@ -21,10 +20,11 @@ import { DatabaseManager } from '../databases';
2120
import { getHtmlForWebview, jumpToLocation } from '../interface-utils';
2221
import { transformBqrsResultSet, RawResultSet, BQRSInfo } from '../pure/bqrs-cli-types';
2322
import resultsDiff from './resultsDiff';
23+
import { FullCompletedQueryInfo } from '../query-results';
2424

2525
interface ComparePair {
26-
from: CompletedQuery;
27-
to: CompletedQuery;
26+
from: FullCompletedQueryInfo;
27+
to: FullCompletedQueryInfo;
2828
}
2929

3030
export class CompareInterfaceManager extends DisposableObject {
@@ -39,15 +39,15 @@ export class CompareInterfaceManager extends DisposableObject {
3939
private cliServer: CodeQLCliServer,
4040
private logger: Logger,
4141
private showQueryResultsCallback: (
42-
item: CompletedQuery
42+
item: FullCompletedQueryInfo
4343
) => Promise<void>
4444
) {
4545
super();
4646
}
4747

4848
async showResults(
49-
from: CompletedQuery,
50-
to: CompletedQuery,
49+
from: FullCompletedQueryInfo,
50+
to: FullCompletedQueryInfo,
5151
selectedResultSetName?: string
5252
) {
5353
this.comparePair = { from, to };
@@ -80,17 +80,13 @@ export class CompareInterfaceManager extends DisposableObject {
8080
// since we split the description into several rows
8181
// only run interpolation if the label is user-defined
8282
// otherwise we will wind up with duplicated rows
83-
name: from.options.label
84-
? from.interpolate(from.getLabel())
85-
: from.queryName,
86-
status: from.statusString,
83+
name: from.getShortLabel(),
84+
status: from.completedQuery.statusString,
8785
time: from.time,
8886
},
8987
toQuery: {
90-
name: to.options.label
91-
? to.interpolate(to.getLabel())
92-
: to.queryName,
93-
status: to.statusString,
88+
name: to.getShortLabel(),
89+
status: to.completedQuery.statusString,
9490
time: to.time,
9591
},
9692
},
@@ -99,7 +95,7 @@ export class CompareInterfaceManager extends DisposableObject {
9995
currentResultSetName: currentResultSetName,
10096
rows,
10197
message,
102-
datebaseUri: to.database.databaseUri,
98+
datebaseUri: to.initialInfo.databaseInfo.databaseUri,
10399
});
104100
}
105101
}
@@ -121,14 +117,14 @@ export class CompareInterfaceManager extends DisposableObject {
121117
],
122118
}
123119
));
124-
this.panel.onDidDispose(
120+
this.push(this.panel.onDidDispose(
125121
() => {
126122
this.panel = undefined;
127123
this.comparePair = undefined;
128124
},
129125
null,
130126
ctx.subscriptions
131-
);
127+
));
132128

133129
const scriptPathOnDisk = Uri.file(
134130
ctx.asAbsolutePath('out/compareView.js')
@@ -143,11 +139,11 @@ export class CompareInterfaceManager extends DisposableObject {
143139
scriptPathOnDisk,
144140
[stylesheetPathOnDisk]
145141
);
146-
panel.webview.onDidReceiveMessage(
142+
this.push(panel.webview.onDidReceiveMessage(
147143
async (e) => this.handleMsgFromView(e),
148144
undefined,
149145
ctx.subscriptions
150-
);
146+
));
151147
}
152148
return this.panel;
153149
}
@@ -191,15 +187,15 @@ export class CompareInterfaceManager extends DisposableObject {
191187
}
192188

193189
private async findCommonResultSetNames(
194-
from: CompletedQuery,
195-
to: CompletedQuery,
190+
from: FullCompletedQueryInfo,
191+
to: FullCompletedQueryInfo,
196192
selectedResultSetName: string | undefined
197193
): Promise<[string[], string, RawResultSet, RawResultSet]> {
198194
const fromSchemas = await this.cliServer.bqrsInfo(
199-
from.query.resultsPaths.resultsPath
195+
from.completedQuery.query.resultsPaths.resultsPath
200196
);
201197
const toSchemas = await this.cliServer.bqrsInfo(
202-
to.query.resultsPaths.resultsPath
198+
to.completedQuery.query.resultsPaths.resultsPath
203199
);
204200
const fromSchemaNames = fromSchemas['result-sets'].map(
205201
(schema) => schema.name
@@ -215,12 +211,12 @@ export class CompareInterfaceManager extends DisposableObject {
215211
const fromResultSet = await this.getResultSet(
216212
fromSchemas,
217213
currentResultSetName,
218-
from.query.resultsPaths.resultsPath
214+
from.completedQuery.query.resultsPaths.resultsPath
219215
);
220216
const toResultSet = await this.getResultSet(
221217
toSchemas,
222218
currentResultSetName,
223-
to.query.resultsPaths.resultsPath
219+
to.completedQuery.query.resultsPaths.resultsPath
224220
);
225221
return [
226222
commonResultSetNames,

extensions/ql-vscode/src/contextual/locationFinder.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import * as vscode from 'vscode';
2-
31
import { decodeSourceArchiveUri, encodeArchiveBasePath } from '../archive-filesystem-provider';
42
import { ColumnKindCode, EntityValue, getResultSetSchema, ResultSetSchema } from '../pure/bqrs-cli-types';
53
import { CodeQLCliServer } from '../cli';
64
import { DatabaseManager, DatabaseItem } from '../databases';
75
import fileRangeFromURI from './fileRangeFromURI';
86
import * as messages from '../pure/messages';
97
import { QueryServerClient } from '../queryserver-client';
10-
import { QueryWithResults, compileAndRunQueryAgainstDatabase } from '../run-queries';
8+
import { QueryWithResults, compileAndRunQueryAgainstDatabase, createInitialQueryInfo } from '../run-queries';
119
import { ProgressCallback } from '../commandRunner';
1210
import { KeyType } from './keyType';
1311
import { qlpackOfDatabase, resolveQueries } from './queryResolver';
12+
import { CancellationToken, LocationLink, Uri } from 'vscode';
1413

1514
export const SELECT_QUERY_NAME = '#select';
1615
export const TEMPLATE_NAME = 'selectedSourceFile';
1716

18-
export interface FullLocationLink extends vscode.LocationLink {
19-
originUri: vscode.Uri;
17+
export interface FullLocationLink extends LocationLink {
18+
originUri: Uri;
2019
}
2120

2221
/**
@@ -40,10 +39,10 @@ export async function getLocationsForUriString(
4039
uriString: string,
4140
keyType: KeyType,
4241
progress: ProgressCallback,
43-
token: vscode.CancellationToken,
42+
token: CancellationToken,
4443
filter: (src: string, dest: string) => boolean
4544
): Promise<FullLocationLink[]> {
46-
const uri = decodeSourceArchiveUri(vscode.Uri.parse(uriString, true));
45+
const uri = decodeSourceArchiveUri(Uri.parse(uriString, true));
4746
const sourceArchiveUri = encodeArchiveBasePath(uri.sourceArchiveZipPath);
4847

4948
const db = dbm.findDatabaseItemBySourceArchive(sourceArchiveUri);
@@ -56,12 +55,20 @@ export async function getLocationsForUriString(
5655

5756
const links: FullLocationLink[] = [];
5857
for (const query of await resolveQueries(cli, qlpack, keyType)) {
58+
const initialInfo = await createInitialQueryInfo(
59+
Uri.file(query),
60+
{
61+
name: db.name,
62+
databaseUri: db.databaseUri.toString(),
63+
},
64+
false
65+
);
66+
5967
const results = await compileAndRunQueryAgainstDatabase(
6068
cli,
6169
qs,
6270
db,
63-
false,
64-
vscode.Uri.file(query),
71+
initialInfo,
6572
progress,
6673
token,
6774
templates

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { CachedOperation } from '../helpers';
1818
import { ProgressCallback, withProgress } from '../commandRunner';
1919
import * as messages from '../pure/messages';
2020
import { QueryServerClient } from '../queryserver-client';
21-
import { compileAndRunQueryAgainstDatabase, QueryWithResults } from '../run-queries';
21+
import { compileAndRunQueryAgainstDatabase, createInitialQueryInfo, QueryWithResults } from '../run-queries';
2222
import AstBuilder from './astBuilder';
2323
import {
2424
KeyType,
@@ -123,15 +123,20 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
123123
}
124124
}
125125

126+
type QueryWithDb = {
127+
query: QueryWithResults,
128+
dbUri: Uri
129+
};
130+
126131
export class TemplatePrintAstProvider {
127-
private cache: CachedOperation<QueryWithResults>;
132+
private cache: CachedOperation<QueryWithDb>;
128133

129134
constructor(
130135
private cli: CodeQLCliServer,
131136
private qs: QueryServerClient,
132137
private dbm: DatabaseManager,
133138
) {
134-
this.cache = new CachedOperation<QueryWithResults>(this.getAst.bind(this));
139+
this.cache = new CachedOperation<QueryWithDb>(this.getAst.bind(this));
135140
}
136141

137142
async provideAst(
@@ -142,13 +147,13 @@ export class TemplatePrintAstProvider {
142147
if (!document) {
143148
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
144149
}
145-
const queryResults = this.shouldCache()
150+
const { query, dbUri } = this.shouldCache()
146151
? await this.cache.get(document.uri.toString(), progress, token)
147152
: await this.getAst(document.uri.toString(), progress, token);
148153

149154
return new AstBuilder(
150-
queryResults, this.cli,
151-
this.dbm.findDatabaseItem(Uri.parse(queryResults.database.databaseUri!, true))!,
155+
query, this.cli,
156+
this.dbm.findDatabaseItem(dbUri)!,
152157
document.fileName
153158
);
154159
}
@@ -161,7 +166,7 @@ export class TemplatePrintAstProvider {
161166
uriString: string,
162167
progress: ProgressCallback,
163168
token: CancellationToken
164-
): Promise<QueryWithResults> {
169+
): Promise<QueryWithDb> {
165170
const uri = Uri.parse(uriString, true);
166171
if (uri.scheme !== zipArchiveScheme) {
167172
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
@@ -195,15 +200,26 @@ export class TemplatePrintAstProvider {
195200
}
196201
};
197202

198-
return await compileAndRunQueryAgainstDatabase(
199-
this.cli,
200-
this.qs,
201-
db,
202-
false,
203+
const initialInfo = await createInitialQueryInfo(
203204
Uri.file(query),
204-
progress,
205-
token,
206-
templates
205+
{
206+
name: db.name,
207+
databaseUri: db.databaseUri.toString(),
208+
},
209+
false
207210
);
211+
212+
return {
213+
query: await compileAndRunQueryAgainstDatabase(
214+
this.cli,
215+
this.qs,
216+
db,
217+
initialInfo,
218+
progress,
219+
token,
220+
templates
221+
),
222+
dbUri: db.databaseUri
223+
};
208224
}
209225
}

0 commit comments

Comments
 (0)