Skip to content

Commit a151862

Browse files
committed
Allow configuring default query history format in settings
Changes to settings should be immediately reflected in query history.
1 parent bf9717a commit a151862

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

extensions/ql-vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
"type": "boolean",
112112
"default": false,
113113
"description": "Enable debug logging and tuple counting when running CodeQL queries. This information is useful for debugging query performance."
114+
},
115+
"codeQL.queryHistory.format": {
116+
"type": "string",
117+
"default": "[%t] %q on %d - %s",
118+
"description": "Default string for how to label query history items. %t is the time of the query, %q is the query name, %d is the database name, and %s is a status string."
114119
}
115120
}
116121
},

extensions/ql-vscode/src/config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const DISTRIBUTION_SETTING = new Setting('cli', ROOT_SETTING);
3737
const CUSTOM_CODEQL_PATH_SETTING = new Setting('executablePath', DISTRIBUTION_SETTING);
3838
const INCLUDE_PRERELEASE_SETTING = new Setting('includePrerelease', DISTRIBUTION_SETTING);
3939
const PERSONAL_ACCESS_TOKEN_SETTING = new Setting('personalAccessToken', DISTRIBUTION_SETTING);
40+
const QUERY_HISTORY_SETTING = new Setting('queryHistory', ROOT_SETTING);
41+
const QUERY_HISTORY_FORMAT_SETTING = new Setting('format', QUERY_HISTORY_SETTING);
4042

4143
/** When these settings change, the distribution should be updated. */
4244
const DISTRIBUTION_CHANGE_SETTINGS = [CUSTOM_CODEQL_PATH_SETTING, INCLUDE_PRERELEASE_SETTING, PERSONAL_ACCESS_TOKEN_SETTING];
@@ -70,6 +72,14 @@ export interface QueryServerConfig {
7072
onDidChangeQueryServerConfiguration?: Event<void>;
7173
}
7274

75+
/** When these settings change, the query history should be refreshed. */
76+
const QUERY_HISTORY_SETTINGS = [QUERY_HISTORY_FORMAT_SETTING];
77+
78+
export interface QueryHistoryConfig {
79+
format: string,
80+
onDidChangeQueryHistoryConfiguration: Event<void>;
81+
}
82+
7383
abstract class ConfigListener extends DisposableObject {
7484
protected readonly _onDidChangeConfiguration = this.push(new EventEmitter<void>());
7585

@@ -176,3 +186,17 @@ export class QueryServerConfigListener extends ConfigListener implements QuerySe
176186
this.handleDidChangeConfigurationForRelevantSettings(QUERY_SERVER_RESTARTING_SETTINGS, e);
177187
}
178188
}
189+
190+
export class QueryHistoryConfigListener extends ConfigListener implements QueryHistoryConfig {
191+
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
192+
this.handleDidChangeConfigurationForRelevantSettings(QUERY_HISTORY_SETTINGS, e);
193+
}
194+
195+
public get onDidChangeQueryHistoryConfiguration(): Event<void> {
196+
return this._onDidChangeConfiguration.event;
197+
}
198+
199+
public get format(): string {
200+
return QUERY_HISTORY_FORMAT_SETTING.getValue<string>();
201+
}
202+
}

extensions/ql-vscode/src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { commands, Disposable, ExtensionContext, extensions, ProgressLocation, ProgressOptions, window as Window, Uri } from 'vscode';
22
import { ErrorCodes, LanguageClient, ResponseError } from 'vscode-languageclient';
33
import * as archiveFilesystemProvider from './archive-filesystem-provider';
4-
import { DistributionConfigListener, QueryServerConfigListener } from './config';
4+
import { DistributionConfigListener, QueryServerConfigListener, QueryHistoryConfigListener } from './config';
55
import { DatabaseManager } from './databases';
66
import { DatabaseUI } from './databases-ui';
77
import { DistributionUpdateCheckResultKind, DistributionManager, FindDistributionResult, FindDistributionResultKind, GithubApiError, DEFAULT_DISTRIBUTION_VERSION_CONSTRAINT } from './distribution';
@@ -230,7 +230,12 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
230230
const databaseUI = new DatabaseUI(ctx, cliServer, dbm, qs);
231231
ctx.subscriptions.push(databaseUI);
232232

233-
const qhm = new QueryHistoryManager(ctx, async item => showResultsForInfo(item.info, WebviewReveal.Forced));
233+
const queryHistoryConfigurationListener = new QueryHistoryConfigListener();
234+
const qhm = new QueryHistoryManager(
235+
ctx,
236+
queryHistoryConfigurationListener,
237+
async item => showResultsForInfo(item.info, WebviewReveal.Forced)
238+
);
234239
const intm = new InterfaceManager(ctx, dbm, cliServer, queryServerLogger);
235240
ctx.subscriptions.push(intm);
236241
archiveFilesystemProvider.activate(ctx);
@@ -248,7 +253,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
248253
}
249254
const info = await compileAndRunQueryAgainstDatabase(cliServer, qs, dbItem, quickEval, selectedQuery);
250255
await showResultsForInfo(info, WebviewReveal.NotForced);
251-
qhm.push(new QueryHistoryItem(info));
256+
qhm.push(info);
252257
}
253258
catch (e) {
254259
if (e instanceof UserCancellationException) {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ExtensionContext, window as Window } from 'vscode';
33
import { EvaluationInfo } from './queries';
44
import * as helpers from './helpers';
55
import * as messages from './messages';
6+
import { QueryHistoryConfig } from './config';
67
/**
78
* query-history.ts
89
* ------------
@@ -23,6 +24,7 @@ export class QueryHistoryItem {
2324

2425
constructor(
2526
info: EvaluationInfo,
27+
public config: QueryHistoryConfig,
2628
public label?: string, // user-settable label
2729
) {
2830
this.queryName = helpers.getQueryName(info);
@@ -65,7 +67,7 @@ export class QueryHistoryItem {
6567
getLabel(): string {
6668
if (this.label !== undefined)
6769
return this.label;
68-
return '[%t] %q on %d - %s';
70+
return this.config.format;
6971
}
7072

7173
toString(): string {
@@ -229,7 +231,11 @@ export class QueryHistoryManager {
229231
}
230232
}
231233

232-
constructor(ctx: ExtensionContext, selectedCallback?: (item: QueryHistoryItem) => Promise<void>) {
234+
constructor(
235+
ctx: ExtensionContext,
236+
private queryHistoryConfigListener: QueryHistoryConfig,
237+
selectedCallback?: (item: QueryHistoryItem) => Promise<void>
238+
) {
233239
this.ctx = ctx;
234240
this.selectedCallback = selectedCallback;
235241
const treeDataProvider = this.treeDataProvider = new HistoryTreeDataProvider(ctx);
@@ -247,9 +253,13 @@ export class QueryHistoryManager {
247253
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.itemClicked', async (item) => {
248254
return this.handleItemClicked(item);
249255
}));
256+
queryHistoryConfigListener.onDidChangeQueryHistoryConfiguration(() => {
257+
this.treeDataProvider.refresh();
258+
});
250259
}
251260

252-
push(item: QueryHistoryItem) {
261+
push(evaluationInfo: EvaluationInfo) {
262+
const item = new QueryHistoryItem(evaluationInfo, this.queryHistoryConfigListener);
253263
this.treeDataProvider.push(item);
254264
this.treeView.reveal(item, { select: true });
255265
}

0 commit comments

Comments
 (0)