Skip to content

Commit eec506a

Browse files
committed
Introduce history-item-label-provider
The label provider is the instance that performs the logic for generating labels for history items, using string interpolation when necessary. This commit creates the label provider and uses it with local queries. Remote queries will be changed in the next commit.
1 parent 542e1d2 commit eec506a

4 files changed

Lines changed: 6 additions & 27 deletions

File tree

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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';
5-
64

75
interface InterpolateReplacements {
86
t: string; // Start time
@@ -20,12 +18,11 @@ export class HistoryItemLabelProvider {
2018
}
2119

2220
getLabel(item: QueryHistoryInfo) {
23-
const replacements = item.t === 'local'
24-
? this.getLocalInterpolateReplacements(item)
25-
: this.getRemoteInterpolateReplacements(item);
26-
21+
if (item.t === 'remote') {
22+
return item.remoteQuery.queryName;
23+
}
24+
const replacements = this.getLocalInterpolateReplacements(item);
2725
const rawLabel = item.userSpecifiedLabel ?? (this.config.format || '%q');
28-
2926
return this.interpolate(rawLabel, replacements);
3027
}
3128

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

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)) {
656+
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem?.t !== 'local') {
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
1314
remoteQuery: RemoteQuery;
14-
userSpecifiedLabel?: string;
1515
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ 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';
2019

2120
/**
2221
* Tests for remote queries and how they interact with the query history manager.
@@ -72,7 +71,6 @@ describe('Remote queries and query history manager', function() {
7271
{
7372
onDidChangeConfiguration: () => new DisposableBucket(),
7473
} as unknown as QueryHistoryConfig,
75-
new HistoryItemLabelProvider({} as QueryHistoryConfig),
7674
asyncNoop
7775
);
7876
disposables.push(qhm);

0 commit comments

Comments
 (0)