Skip to content

Commit 2f5a306

Browse files
committed
Simplify the query history objects to make them serializable
The goal with this change is to simplify the query history to make it possible to serialize and de serialize. This change adds serialization support. Since query history objects are complex, the de-serialization requires manipulation of the de serialized object prototypes.
1 parent 0ef6b45 commit 2f5a306

12 files changed

Lines changed: 402 additions & 164 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
## [UNRELEASED]
44

55
- Fix a bug where invoking _View AST_ from the file explorer would not view the selected file. Instead it would view the active editor. Also, prevent the _View AST_ from appearing if the current selection includes a directory or multiple files. [#1113](https://github.com/github/vscode-codeql/pull/1113)
6+
- Add query history items as soon as a query is run, including new icons for each history item. [#1094](https://github.com/github/vscode-codeql/pull/1094)
67

78
## 1.5.10 - 25 January 2022
89

910
- Fix a bug where the results view moved column even when it was already visible. [#1070](https://github.com/github/vscode-codeql/pull/1070)
1011
- Add packaging-related commands. _CodeQL: Download Packs_ downloads query packs from the package registry that can be run locally, and _CodeQL: Install Pack Dependencies_ installs dependencies for packs in your workspace. [#1076](https://github.com/github/vscode-codeql/pull/1076)
11-
- Add query history items as soon as a query is run, including new icons for each history item. [#1094](https://github.com/github/vscode-codeql/pull/1094)
1212

1313
## 1.5.9 - 17 December 2021
1414

extensions/ql-vscode/package-lock.json

Lines changed: 45 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@
10211021
"glob-promise": "^3.4.0",
10221022
"js-yaml": "^3.14.0",
10231023
"minimist": "~1.2.5",
1024+
"nanoid": "^3.2.0",
10241025
"node-fetch": "~2.6.7",
10251026
"path-browserify": "^1.0.1",
10261027
"react": "^17.0.2",
@@ -1056,6 +1057,7 @@
10561057
"@types/js-yaml": "^3.12.5",
10571058
"@types/jszip": "~3.1.6",
10581059
"@types/mocha": "^9.0.0",
1060+
"@types/nanoid": "^3.0.0",
10591061
"@types/node": "^12.14.1",
10601062
"@types/node-fetch": "~2.5.2",
10611063
"@types/proxyquire": "~1.3.28",

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ async function activateWithInstalledDistribution(
438438

439439
const qhm = new QueryHistoryManager(
440440
qs,
441+
dbm,
441442
ctx.extensionPath,
442443
queryHistoryConfigurationListener,
443444
showResults,

extensions/ql-vscode/src/interface.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export class InterfaceManager extends DisposableObject {
316316
// sortedResultsInfo doesn't have an entry for the current
317317
// result set. Use this to determine whether or not we use
318318
// the sorted bqrs file.
319-
this._displayedQuery?.completedQuery.sortedResultsInfo.has(msg.selectedTable) || false
319+
!!this._displayedQuery?.completedQuery.sortedResultsInfo[msg.selectedTable] || false
320320
);
321321
}
322322
break;
@@ -372,8 +372,8 @@ export class InterfaceManager extends DisposableObject {
372372
);
373373

374374
const sortedResultsMap: SortedResultsMap = {};
375-
fullQuery.completedQuery.sortedResultsInfo.forEach(
376-
(v, k) =>
375+
Object.entries(fullQuery.completedQuery.sortedResultsInfo).forEach(
376+
([k, v]) =>
377377
(sortedResultsMap[k] = this.convertPathPropertiesToWebviewUris(v))
378378
);
379379

@@ -458,7 +458,7 @@ export class InterfaceManager extends DisposableObject {
458458
shouldKeepOldResultsWhileRendering,
459459
metadata: fullQuery.completedQuery.query.metadata,
460460
queryName: fullQuery.label,
461-
queryPath: fullQuery.completedQuery.query.program.queryPath
461+
queryPath: fullQuery.initialInfo.queryPath
462462
});
463463
}
464464

@@ -491,7 +491,7 @@ export class InterfaceManager extends DisposableObject {
491491
pageSize: PAGE_SIZE.getValue(),
492492
numPages: numInterpretedPages(this._interpretation),
493493
queryName: this._displayedQuery.label,
494-
queryPath: this._displayedQuery.completedQuery.query.program.queryPath
494+
queryPath: this._displayedQuery.initialInfo.queryPath
495495
});
496496
}
497497

@@ -523,8 +523,8 @@ export class InterfaceManager extends DisposableObject {
523523
}
524524

525525
const sortedResultsMap: SortedResultsMap = {};
526-
results.completedQuery.sortedResultsInfo.forEach(
527-
(v, k) =>
526+
Object.entries(results.completedQuery.sortedResultsInfo).forEach(
527+
([k, v]) =>
528528
(sortedResultsMap[k] = this.convertPathPropertiesToWebviewUris(v))
529529
);
530530

@@ -576,7 +576,7 @@ export class InterfaceManager extends DisposableObject {
576576
shouldKeepOldResultsWhileRendering: false,
577577
metadata: results.completedQuery.query.metadata,
578578
queryName: results.label,
579-
queryPath: results.completedQuery.query.program.queryPath
579+
queryPath: results.initialInfo.queryPath
580580
});
581581
}
582582

@@ -649,14 +649,18 @@ export class InterfaceManager extends DisposableObject {
649649
sortState: InterpretedResultsSortState | undefined
650650
): Promise<Interpretation | undefined> {
651651
if (
652-
(await query.canHaveInterpretedResults()) &&
652+
query.canHaveInterpretedResults() &&
653653
query.quickEvalPosition === undefined // never do results interpretation if quickEval
654654
) {
655655
try {
656-
const sourceLocationPrefix = await query.dbItem.getSourceLocationPrefix(
656+
const dbItem = this.databaseManager.findDatabaseItem(Uri.file(query.dbItemPath));
657+
if (!dbItem) {
658+
throw new Error(`Could not find database item for ${query.dbItemPath}`);
659+
}
660+
const sourceLocationPrefix = await dbItem.getSourceLocationPrefix(
657661
this.cliServer
658662
);
659-
const sourceArchiveUri = query.dbItem.sourceArchive;
663+
const sourceArchiveUri = dbItem.sourceArchive;
660664
const sourceInfo =
661665
sourceArchiveUri === undefined
662666
? undefined

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { DisposableObject } from './pure/disposable-object';
2828
import { commandRunner } from './commandRunner';
2929
import { assertNever } from './pure/helpers-pure';
3030
import { FullCompletedQueryInfo, FullQueryInfo, QueryStatus } from './query-results';
31+
import { DatabaseManager } from './databases';
3132

3233
/**
3334
* query-history.ts
@@ -246,6 +247,7 @@ export class QueryHistoryManager extends DisposableObject {
246247

247248
constructor(
248249
private qs: QueryServerClient,
250+
private dbm: DatabaseManager,
249251
extensionPath: string,
250252
queryHistoryConfigListener: QueryHistoryConfig,
251253
private selectedCallback: (item: FullCompletedQueryInfo) => Promise<void>,
@@ -599,14 +601,12 @@ export class QueryHistoryManager extends DisposableObject {
599601
throw new Error(NO_QUERY_SELECTED);
600602
}
601603

602-
const rawQueryName = singleItem.getQueryName();
603-
const queryName = rawQueryName.endsWith('.ql') ? rawQueryName : rawQueryName + '.ql';
604604
const params = new URLSearchParams({
605605
isQuickEval: String(!!singleItem.initialInfo.quickEvalPosition),
606606
queryText: encodeURIComponent(await this.getQueryText(singleItem)),
607607
});
608608
const uri = Uri.parse(
609-
`codeql:${singleItem.initialInfo.id}-${queryName}?${params.toString()}`, true
609+
`codeql:${singleItem.initialInfo.id}?${params.toString()}`, true
610610
);
611611
const doc = await workspace.openTextDocument(uri);
612612
await window.showTextDocument(doc, { preview: false });
@@ -620,7 +620,7 @@ export class QueryHistoryManager extends DisposableObject {
620620
return;
621621
}
622622
const query = singleItem.completedQuery.query;
623-
const hasInterpretedResults = await query.canHaveInterpretedResults();
623+
const hasInterpretedResults = query.canHaveInterpretedResults();
624624
if (hasInterpretedResults) {
625625
await this.tryOpenExternalFile(
626626
query.resultsPaths.interpretedResultsPath
@@ -664,7 +664,7 @@ export class QueryHistoryManager extends DisposableObject {
664664
}
665665

666666
await this.tryOpenExternalFile(
667-
await singleItem.completedQuery.query.ensureCsvProduced(this.qs)
667+
await singleItem.completedQuery.query.ensureCsvProduced(this.qs, this.dbm)
668668
);
669669
}
670670

0 commit comments

Comments
 (0)