Skip to content

Commit 3a43cfe

Browse files
committed
Allow simple templating of query history labels
1 parent 52b8384 commit 3a43cfe

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,29 @@ export class QueryHistoryItem {
4747
}
4848
}
4949

50-
toString(): string {
50+
interpolate(template: string): string {
51+
const { databaseName, queryName, time, statusString } = this;
52+
const replacements: { [k: string]: string } = {
53+
t: time,
54+
q: queryName,
55+
d: databaseName,
56+
s: statusString,
57+
'%': '%',
58+
};
59+
return template.replace(/%(.)/g, (match, key) => {
60+
const replacement = replacements[key];
61+
return replacement !== undefined ? replacement : match;
62+
});
63+
}
64+
65+
getLabel(): string {
5166
if (this.label !== undefined)
5267
return this.label;
68+
return '[%t] %q on %d - %s';
69+
}
5370

54-
const { databaseName, queryName, time } = this;
55-
return `[${time}] ${queryName} on ${databaseName} - ${this.statusString}`;
71+
toString(): string {
72+
return this.interpolate(this.getLabel());
5673
}
5774
}
5875

@@ -178,9 +195,9 @@ export class QueryHistoryManager {
178195

179196
async handleSetLabel(queryHistoryItem: QueryHistoryItem) {
180197
const response = await vscode.window.showInputBox({
181-
prompt: 'Label: ',
198+
prompt: 'Label:',
182199
placeHolder: '(use default)',
183-
value: queryHistoryItem.toString(),
200+
value: queryHistoryItem.getLabel(),
184201
});
185202
// undefined response means the user cancelled the dialog; don't change anything
186203
if (response !== undefined) {

0 commit comments

Comments
 (0)