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.
This commit is contained in:
Andrew Eisenberg
2022-04-12 12:35:01 -07:00
parent 542e1d24aa
commit eec506a209
4 changed files with 6 additions and 27 deletions

View File

@@ -1,8 +1,6 @@
import { env } from 'vscode';
import { QueryHistoryConfig } from './config';
import { LocalQueryInfo, QueryHistoryInfo } from './query-results';
import { RemoteQueryHistoryItem } from './remote-queries/remote-query-history-item';
interface InterpolateReplacements {
t: string; // Start time
@@ -20,12 +18,11 @@ export class HistoryItemLabelProvider {
}
getLabel(item: QueryHistoryInfo) {
const replacements = item.t === 'local'
? this.getLocalInterpolateReplacements(item)
: this.getRemoteInterpolateReplacements(item);
if (item.t === 'remote') {
return item.remoteQuery.queryName;
}
const replacements = this.getLocalInterpolateReplacements(item);
const rawLabel = item.userSpecifiedLabel ?? (this.config.format || '%q');
return this.interpolate(rawLabel, replacements);
}
@@ -63,20 +60,4 @@ export class HistoryItemLabelProvider {
'%': '%',
};
}
private getRemoteInterpolateReplacements(item: RemoteQueryHistoryItem): InterpolateReplacements {
return {
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(env.language),
q: item.remoteQuery.queryName,
// There is no database name for remote queries. Instead use the controller repository name.
d: `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`,
// There is no synchronous way to get the results count.
r: '',
s: item.status,
f: item.remoteQuery.queryFilePath,
'%': '%'
};
}
}

View File

@@ -653,7 +653,7 @@ export class QueryHistoryManager extends DisposableObject {
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
// TODO will support remote queries
if (!this.assertSingleQuery(finalMultiSelect)) {
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem?.t !== 'local') {
return;
}

View File

@@ -10,6 +10,6 @@ export interface RemoteQueryHistoryItem {
status: QueryStatus;
completed: boolean;
readonly queryId: string,
label: string; // TODO, the query label should have interpolation like local queries
remoteQuery: RemoteQuery;
userSpecifiedLabel?: string;
}

View File

@@ -16,7 +16,6 @@ import { DisposableBucket } from '../../disposable-bucket';
import { testDisposeHandler } from '../../test-dispose-handler';
import { walkDirectory } from '../../../helpers';
import { getErrorMessage } from '../../../pure/helpers-pure';
import { HistoryItemLabelProvider } from '../../../history-item-label-provider';
/**
* 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() {
{
onDidChangeConfiguration: () => new DisposableBucket(),
} as unknown as QueryHistoryConfig,
new HistoryItemLabelProvider({} as QueryHistoryConfig),
asyncNoop
);
disposables.push(qhm);