Skip to content

Commit 6793f8e

Browse files
committed
feat: Adds command to show query log in editor
Right clicking on the history page will now have a new option to show the associated log. Closes #236 Closes #234
1 parent da28beb commit 6793f8e

File tree

8 files changed

+54
-2
lines changed

8 files changed

+54
-2
lines changed

extensions/ql-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@
208208
"command": "codeQLQueryHistory.itemClicked",
209209
"title": "Query History Item"
210210
},
211+
{
212+
"command": "codeQLQueryHistory.showQueryLog",
213+
"title": "Show Query Log"
214+
},
211215
{
212216
"command": "codeQLQueryResults.nextPathStep",
213217
"title": "CodeQL: Show Next Step on Path"
@@ -272,6 +276,11 @@
272276
"group": "9_qlCommands",
273277
"when": "view == codeQLQueryHistory"
274278
},
279+
{
280+
"command": "codeQLQueryHistory.showQueryLog",
281+
"group": "9_qlCommands",
282+
"when": "view == codeQLQueryHistory"
283+
},
275284
{
276285
"command": "codeQLTests.showOutputDifferences",
277286
"group": "qltest@1",
@@ -328,6 +337,10 @@
328337
"command": "codeQLQueryHistory.itemClicked",
329338
"when": "false"
330339
},
340+
{
341+
"command": "codeQLQueryHistory.showQueryLog",
342+
"when": "false"
343+
},
331344
{
332345
"command": "codeQLQueryHistory.setLabel",
333346
"when": "false"

extensions/ql-vscode/src/logging.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export interface Logger {
2626
* @param location log to remove
2727
*/
2828
removeAdditionalLogLocation(location: string): void;
29+
30+
/**
31+
* The base location location where all side log files are stored.
32+
*/
33+
getBaseLocation(): string | undefined;
2934
}
3035

3136
export type ProgressReporter = Progress<{ message: string }>;
@@ -98,6 +103,10 @@ export class OutputChannelLogger extends DisposableObject implements Logger {
98103
}
99104
}
100105
}
106+
107+
getBaseLocation() {
108+
return this.additionalLogLocationPath;
109+
}
101110
}
102111

103112
class AdditionalLogLocation extends Disposable {

extensions/ql-vscode/src/messages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,11 @@ export interface EvaluationResult {
778778
* An error message if an error happened
779779
*/
780780
message?: string;
781+
782+
/**
783+
* Full path to file with all log messages emitted while this query was active, if one exists
784+
*/
785+
logFileLocation?: string;
781786
}
782787

783788
export type QueryResultType = number;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ExtensionContext, window as Window } from 'vscode';
44
import { CompletedQuery } from './query-results';
55
import { QueryHistoryConfig } from './config';
66
import { QueryWithResults } from './run-queries';
7+
import * as helpers from './helpers';
78

89
/**
910
* query-history.ts
@@ -187,6 +188,20 @@ export class QueryHistoryManager {
187188
}
188189
}
189190

191+
async handleShowQueryLog(queryHistoryItem: CompletedQuery) {
192+
if (queryHistoryItem.logFileLocation) {
193+
try {
194+
await vscode.window.showTextDocument(vscode.Uri.parse(queryHistoryItem.logFileLocation), {
195+
viewColumn: vscode.ViewColumn.Beside
196+
});
197+
} catch (e) {
198+
helpers.showAndLogErrorMessage(`Could not open log file ${queryHistoryItem.logFileLocation}`);
199+
}
200+
} else {
201+
helpers.showAndLogWarningMessage('No log file available');
202+
}
203+
}
204+
190205
constructor(
191206
ctx: ExtensionContext,
192207
private queryHistoryConfigListener: QueryHistoryConfig,
@@ -208,6 +223,7 @@ export class QueryHistoryManager {
208223
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.openQuery', this.handleOpenQuery));
209224
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.removeHistoryItem', this.handleRemoveHistoryItem.bind(this)));
210225
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.setLabel', this.handleSetLabel.bind(this)));
226+
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.showQueryLog', this.handleShowQueryLog.bind(this)));
211227
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.itemClicked', async (item) => {
212228
return this.handleItemClicked(item);
213229
}));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class CompletedQuery implements QueryWithResults {
1414
readonly query: QueryInfo;
1515
readonly result: messages.EvaluationResult;
1616
readonly database: DatabaseInfo;
17+
readonly logFileLocation?: string
1718
options: QueryHistoryItemOptions;
1819

1920
/**
@@ -37,6 +38,7 @@ export class CompletedQuery implements QueryWithResults {
3738
this.query = evalaution.query;
3839
this.result = evalaution.result;
3940
this.database = evalaution.database;
41+
this.logFileLocation = evalaution.logFileLocation;
4042
this.time = new Date().toLocaleString();
4143
this.sortedResultsInfo = new Map();
4244
this.options = evalaution.options;

extensions/ql-vscode/src/queryserver-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ export class QueryServerClient extends DisposableObject {
129129
this.logger.log(`No callback associated with run id ${res.runId}, continuing without executing any callback`);
130130
}
131131
else {
132+
const baseLocation = this.logger.getBaseLocation();
133+
if (baseLocation && this.activeQueryName) {
134+
res.logFileLocation = path.join(baseLocation, this.activeQueryName);
135+
}
132136
this.evaluationResultCallbacks[res.runId](res);
133137
}
134138
return {};

extensions/ql-vscode/src/run-queries.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export interface QueryWithResults {
174174
readonly result: messages.EvaluationResult;
175175
readonly database: DatabaseInfo;
176176
readonly options: QueryHistoryItemOptions;
177+
readonly logFileLocation?: string;
177178
}
178179

179180
export async function clearCacheInDatabase(
@@ -462,7 +463,8 @@ export async function compileAndRunQueryAgainstDatabase(
462463
name: db.name,
463464
databaseUri: db.databaseUri.toString(true)
464465
},
465-
options: historyItemOptions
466+
options: historyItemOptions,
467+
logFileLocation: result.logFileLocation
466468
};
467469
} else {
468470
// Error dialogs are limited in size and scrollability,

extensions/ql-vscode/test/pure-tests/query-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ describe('using the query server', function() {
107107
const logger: Logger = {
108108
log: async (s: string) => console.log('logger says', s),
109109
show: () => { /**/ },
110-
removeAdditionalLogLocation: async () => { /**/ }
110+
removeAdditionalLogLocation: async () => { /**/ },
111+
getBaseLocation: () => ''
111112
};
112113
cliServer = new cli.CodeQLCliServer({
113114
async getCodeQlPathWithoutVersionCheck(): Promise<string | undefined> {

0 commit comments

Comments
 (0)