Skip to content

Commit f1c4fef

Browse files
committed
Allow remote query items to have their labels edited
The labels for remote query items are interpolated using the same strategy as local queries with two caveats: 1. There is no easy way to get the result count without reading files, so, this value is kept empty. 2. There is no database name for remote queries. Instead, use the nwo of the controller repo. Also, adds tests for the history item label provider.
1 parent eec506a commit f1c4fef

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

extensions/ql-vscode/src/history-item-label-provider.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { env } from 'vscode';
22
import { QueryHistoryConfig } from './config';
33
import { LocalQueryInfo, QueryHistoryInfo } from './query-results';
4+
import { RemoteQueryHistoryItem } from './remote-queries/remote-query-history-item';
45

56
interface InterpolateReplacements {
67
t: string; // Start time
@@ -18,11 +19,12 @@ export class HistoryItemLabelProvider {
1819
}
1920

2021
getLabel(item: QueryHistoryInfo) {
21-
if (item.t === 'remote') {
22-
return item.remoteQuery.queryName;
23-
}
24-
const replacements = this.getLocalInterpolateReplacements(item);
22+
const replacements = item.t === 'local'
23+
? this.getLocalInterpolateReplacements(item)
24+
: this.getRemoteInterpolateReplacements(item);
25+
2526
const rawLabel = item.userSpecifiedLabel ?? (this.config.format || '%q');
27+
2628
return this.interpolate(rawLabel, replacements);
2729
}
2830

@@ -60,4 +62,20 @@ export class HistoryItemLabelProvider {
6062
'%': '%',
6163
};
6264
}
65+
66+
private getRemoteInterpolateReplacements(item: RemoteQueryHistoryItem): InterpolateReplacements {
67+
return {
68+
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(env.language),
69+
q: item.remoteQuery.queryName,
70+
71+
// There is no database name for remote queries. Instead use the controller repository name.
72+
d: `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`,
73+
74+
// There is no synchronous way to get the results count.
75+
r: '',
76+
s: item.status,
77+
f: item.remoteQuery.queryFilePath,
78+
'%': '%'
79+
};
80+
}
6381
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export class QueryHistoryManager extends DisposableObject {
653653
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
654654

655655
// TODO will support remote queries
656-
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem?.t !== 'local') {
656+
if (!this.assertSingleQuery(finalMultiSelect)) {
657657
return;
658658
}
659659

extensions/ql-vscode/src/remote-queries/remote-query-history-item.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export interface RemoteQueryHistoryItem {
1010
status: QueryStatus;
1111
completed: boolean;
1212
readonly queryId: string,
13-
label: string; // TODO, the query label should have interpolation like local queries
1413
remoteQuery: RemoteQuery;
14+
userSpecifiedLabel?: string;
1515
}

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/remote-query-history.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { DisposableBucket } from '../../disposable-bucket';
1616
import { testDisposeHandler } from '../../test-dispose-handler';
1717
import { walkDirectory } from '../../../helpers';
1818
import { getErrorMessage } from '../../../pure/helpers-pure';
19+
import { HistoryItemLabelProvider } from '../../../history-item-label-provider';
1920

2021
/**
2122
* Tests for remote queries and how they interact with the query history manager.
@@ -71,6 +72,7 @@ describe('Remote queries and query history manager', function() {
7172
{
7273
onDidChangeConfiguration: () => new DisposableBucket(),
7374
} as unknown as QueryHistoryConfig,
75+
new HistoryItemLabelProvider({} as QueryHistoryConfig),
7476
asyncNoop
7577
);
7678
disposables.push(qhm);

0 commit comments

Comments
 (0)