Skip to content

Commit 213f4ce

Browse files
authored
Merge branch 'main' into aeisenberg/settings
2 parents 5580095 + 2d17267 commit 213f4ce

5 files changed

Lines changed: 98 additions & 182 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Fix a bug where the AST viewer was not synchronizing its selected node when the editor selection changes. [#1230](https://github.com/github/vscode-codeql/pull/1230)
66
- Avoid synchronizing the `codeQL.cli.executablePath` setting. [#1252](https://github.com/github/vscode-codeql/pull/1252)
7+
- Open the directory in the finder/explorer (instead of just highlighting it) when running the "Open query directory" command from the query history view. [#1235](https://github.com/github/vscode-codeql/pull/1235)
8+
- Ensure query label in the query history view changes are persisted across restarts. [#1235](https://github.com/github/vscode-codeql/pull/1235)
79

810
## 1.6.1 - 17 March 2022
911

extensions/ql-vscode/package-lock.json

Lines changed: 20 additions & 136 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@
11751175
"@types/tmp": "^0.1.0",
11761176
"@types/unzipper": "~0.10.1",
11771177
"@types/vscode": "^1.59.0",
1178-
"@types/webpack": "^4.32.1",
1178+
"@types/webpack": "^5.28.0",
11791179
"@types/xml2js": "~0.4.4",
11801180
"@typescript-eslint/eslint-plugin": "^4.26.0",
11811181
"@typescript-eslint/parser": "^4.26.0",

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

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { URLSearchParams } from 'url';
2828
import { QueryServerClient } from './queryserver-client';
2929
import { DisposableObject } from './pure/disposable-object';
3030
import { commandRunner } from './commandRunner';
31-
import { assertNever, ONE_HOUR_IN_MS, TWO_HOURS_IN_MS, getErrorMessage, getErrorStack } from './pure/helpers-pure';
31+
import { assertNever, ONE_HOUR_IN_MS, TWO_HOURS_IN_MS, getErrorMessage, getErrorStack } from './pure/helpers-pure';
3232
import { CompletedLocalQueryInfo, LocalQueryInfo as LocalQueryInfo, QueryHistoryInfo } from './query-results';
3333
import { DatabaseManager } from './databases';
3434
import { registerQueryHistoryScubber } from './query-history-scrubber';
@@ -183,38 +183,48 @@ export class HistoryTreeDataProvider extends DisposableObject {
183183
): ProviderResult<QueryHistoryInfo[]> {
184184
return element ? [] : this.history.sort((h1, h2) => {
185185

186-
// TODO remote queries are not implemented yet.
187-
if (h1.t !== 'local' && h2.t !== 'local') {
188-
return 0;
189-
}
190-
if (h1.t !== 'local') {
191-
return -1;
192-
}
193-
if (h2.t !== 'local') {
194-
return 1;
195-
}
186+
const h1Label = h1.label.toLowerCase();
187+
const h2Label = h2.label.toLowerCase();
188+
189+
const h1Date = h1.t === 'local'
190+
? h1.initialInfo.start.getTime()
191+
: h1.remoteQuery?.executionStartTime;
196192

197-
const resultCount1 = h1.completedQuery?.resultCount ?? -1;
198-
const resultCount2 = h2.completedQuery?.resultCount ?? -1;
193+
const h2Date = h2.t === 'local'
194+
? h2.initialInfo.start.getTime()
195+
: h2.remoteQuery?.executionStartTime;
196+
197+
// result count for remote queries is not available here.
198+
const resultCount1 = h1.t === 'local'
199+
? h1.completedQuery?.resultCount ?? -1
200+
: -1;
201+
const resultCount2 = h2.t === 'local'
202+
? h2.completedQuery?.resultCount ?? -1
203+
: -1;
199204

200205
switch (this.sortOrder) {
201206
case SortOrder.NameAsc:
202-
return h1.label.localeCompare(h2.label, env.language);
207+
return h1Label.localeCompare(h2Label, env.language);
208+
203209
case SortOrder.NameDesc:
204-
return h2.label.localeCompare(h1.label, env.language);
210+
return h2Label.localeCompare(h1Label, env.language);
211+
205212
case SortOrder.DateAsc:
206-
return h1.initialInfo.start.getTime() - h2.initialInfo.start.getTime();
213+
return h1Date - h2Date;
214+
207215
case SortOrder.DateDesc:
208-
return h2.initialInfo.start.getTime() - h1.initialInfo.start.getTime();
216+
return h2Date - h1Date;
217+
209218
case SortOrder.CountAsc:
210219
// If the result counts are equal, sort by name.
211220
return resultCount1 - resultCount2 === 0
212-
? h1.label.localeCompare(h2.label, env.language)
221+
? h1Label.localeCompare(h2Label, env.language)
213222
: resultCount1 - resultCount2;
223+
214224
case SortOrder.CountDesc:
215225
// If the result counts are equal, sort by name.
216226
return resultCount2 - resultCount1 === 0
217-
? h2.label.localeCompare(h1.label, env.language)
227+
? h2Label.localeCompare(h1Label, env.language)
218228
: resultCount2 - resultCount1;
219229
default:
220230
assertNever(this.sortOrder);
@@ -650,7 +660,7 @@ export class QueryHistoryManager extends DisposableObject {
650660
if (response !== undefined) {
651661
// Interpret empty string response as 'go back to using default'
652662
finalSingleItem.initialInfo.userSpecifiedLabel = response === '' ? undefined : response;
653-
this.treeDataProvider.refresh();
663+
await this.refreshTreeView();
654664
}
655665
}
656666

@@ -741,24 +751,32 @@ export class QueryHistoryManager extends DisposableObject {
741751
return;
742752
}
743753

744-
let p: string | undefined;
754+
let externalFilePath: string | undefined;
745755
if (finalSingleItem.t === 'local') {
746756
if (finalSingleItem.completedQuery) {
747-
p = finalSingleItem.completedQuery.query.querySaveDir;
757+
externalFilePath = path.join(finalSingleItem.completedQuery.query.querySaveDir, 'timestamp');
748758
}
749759
} else if (finalSingleItem.t === 'remote') {
750-
p = path.join(this.queryStorageDir, finalSingleItem.queryId);
760+
externalFilePath = path.join(this.queryStorageDir, finalSingleItem.queryId, 'timestamp');
751761
}
752762

753-
if (p) {
763+
if (externalFilePath) {
764+
if (!(await fs.pathExists(externalFilePath))) {
765+
// timestamp file is missing (manually deleted?) try selecting the parent folder.
766+
// It's less nice, but at least it will work.
767+
externalFilePath = path.dirname(externalFilePath);
768+
if (!(await fs.pathExists(externalFilePath))) {
769+
throw new Error(`Query directory does not exist: ${externalFilePath}`);
770+
}
771+
}
754772
try {
755-
await commands.executeCommand('revealFileInOS', Uri.file(p));
773+
await commands.executeCommand('revealFileInOS', Uri.file(externalFilePath));
756774
} catch (e) {
757-
throw new Error(`Failed to open ${p}: ${getErrorMessage(e)}`);
775+
throw new Error(`Failed to open ${externalFilePath}: ${getErrorMessage(e)}`);
758776
}
759777
}
760778
}
761-
779+
762780
private warnNoEvalLog() {
763781
void showAndLogWarningMessage('No evaluator log is available for this run. Perhaps it failed before evaluation, or you are running with a version of CodeQL before ' + CliVersionConstraint.CLI_VERSION_WITH_PER_QUERY_EVAL_LOG + '?');
764782
}

0 commit comments

Comments
 (0)