diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 0b960b34729..e20f1ffb7a7 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -6,6 +6,7 @@ - Open the query server logs for query errors (instead of the extension log). This will make it easier to track down query errors. [#1158](https://github.com/github/vscode-codeql/pull/1158) - Fix a bug where queries took a long time to run if there are no folders in the workspace. [#1157](https://github.com/github/vscode-codeql/pull/1157) - [BREAKING CHANGE] The `codeQL.runningQueries.customLogDirectory` setting is deprecated and no longer has any function. Instead, all query log files will be stored in the query history directory, next to the query results. [#1178](https://github.com/github/vscode-codeql/pull/1178) +- Add a _Open query directory_ command for query items. This command opens the directory containing all artifacts for a query. [#1179](https://github.com/github/vscode-codeql/pull/1179) ## 1.5.11 - 10 February 2022 diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 47502c85f13..1a06cd6929c 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -508,6 +508,10 @@ "command": "codeQLQueryHistory.showQueryLog", "title": "Show Query Log" }, + { + "command": "codeQLQueryHistory.openQueryDirectory", + "title": "Open query directory" + }, { "command": "codeQLQueryHistory.cancel", "title": "Cancel" @@ -697,6 +701,11 @@ "group": "9_qlCommands", "when": "viewItem == rawResultsItem || viewItem == interpretedResultsItem" }, + { + "command": "codeQLQueryHistory.openQueryDirectory", + "group": "9_qlCommands", + "when": "view == codeQLQueryHistory && !hasRemoteServer" + }, { "command": "codeQLQueryHistory.showQueryText", "group": "9_qlCommands", @@ -887,6 +896,10 @@ "command": "codeQLQueryHistory.showQueryLog", "when": "false" }, + { + "command": "codeQLQueryHistory.openQueryDirectory", + "when": "false" + }, { "command": "codeQLQueryHistory.cancel", "when": "false" diff --git a/extensions/ql-vscode/src/query-history.ts b/extensions/ql-vscode/src/query-history.ts index 827b1090e5f..588a78339a2 100644 --- a/extensions/ql-vscode/src/query-history.ts +++ b/extensions/ql-vscode/src/query-history.ts @@ -400,6 +400,12 @@ export class QueryHistoryManager extends DisposableObject { this.handleShowQueryLog.bind(this) ) ); + this.push( + commandRunner( + 'codeQLQueryHistory.openQueryDirectory', + this.handleOpenQueryDirectory.bind(this) + ) + ); this.push( commandRunner( 'codeQLQueryHistory.cancel', @@ -703,6 +709,34 @@ export class QueryHistoryManager extends DisposableObject { } } + async handleOpenQueryDirectory( + singleItem: QueryHistoryInfo, + multiSelect: QueryHistoryInfo[] + ) { + const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect); + + if (!this.assertSingleQuery(finalMultiSelect) || !finalSingleItem) { + return; + } + + let p: string | undefined; + if (finalSingleItem.t === 'local') { + if (finalSingleItem.completedQuery) { + p = finalSingleItem.completedQuery.query.querySaveDir; + } + } else if (finalSingleItem.t === 'remote') { + p = path.join(this.queryStorageDir, finalSingleItem.queryId); + } + + if (p) { + try { + await commands.executeCommand('revealFileInOS', Uri.file(p)); + } catch (e) { + throw new Error(`Failed to open ${p}: ${e.message}`); + } + } + } + async handleCancel( singleItem: QueryHistoryInfo, multiSelect: QueryHistoryInfo[] diff --git a/extensions/ql-vscode/src/remote-queries/remote-query-history-item.ts b/extensions/ql-vscode/src/remote-queries/remote-query-history-item.ts index f2c8ae9931f..ea27df89a4f 100644 --- a/extensions/ql-vscode/src/remote-queries/remote-query-history-item.ts +++ b/extensions/ql-vscode/src/remote-queries/remote-query-history-item.ts @@ -10,6 +10,6 @@ export interface RemoteQueryHistoryItem { status: QueryStatus; completed: boolean; readonly queryId: string, - label: string, // TODO, the query label should have interpolation like local queries - remoteQuery: RemoteQuery, + label: string; // TODO, the query label should have interpolation like local queries + remoteQuery: RemoteQuery; } diff --git a/extensions/ql-vscode/src/run-queries.ts b/extensions/ql-vscode/src/run-queries.ts index a13a6544c73..37bfffc197c 100644 --- a/extensions/ql-vscode/src/run-queries.ts +++ b/extensions/ql-vscode/src/run-queries.ts @@ -67,7 +67,7 @@ export class QueryEvaluationInfo { * by explicitly setting the prototype in order to avoid calling this constructor. */ constructor( - private readonly querySaveDir: string, + public readonly querySaveDir: string, public readonly dbItemPath: string, private readonly databaseHasMetadataFile: boolean, public readonly queryDbscheme: string, // the dbscheme file the query expects, based on library path resolution