Skip to content

Commit 895ac6a

Browse files
committed
Squash extra whitespace for Query History labels
We'd like to remove duplicate whitespace in these labels in order to make it less likely that we introduce extra space. We initially also tried trimming whitespaces at the start and end of these labels but that had no effect.
1 parent 52484f1 commit 895ac6a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ export class HistoryItemLabelProvider {
4646

4747

4848
private interpolate(rawLabel: string, replacements: InterpolateReplacements): string {
49-
return rawLabel.replace(/%(.)/g, (match, key: keyof InterpolateReplacements) => {
49+
const label = rawLabel.replace(/%(.)/g, (match, key: keyof InterpolateReplacements) => {
5050
const replacement = replacements[key];
5151
return replacement !== undefined ? replacement : match;
5252
});
53+
54+
return label.replace(/\s+/g, ' ');
5355
}
5456

5557
private getLocalInterpolateReplacements(item: LocalQueryInfo): InterpolateReplacements {

extensions/ql-vscode/src/vscode-tests/no-workspace/history-item-label-provider.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,31 @@ describe('HistoryItemLabelProvider', () => {
138138
it('should skip displaying them', () => {
139139
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
140140
config.format = '%t %q %d %s %f %r %%';
141-
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
141+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
142+
});
143+
});
144+
145+
describe('when extra whitespace is present in the middle of the label', () => {
146+
it('should squash it down to a single whitespace', () => {
147+
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
148+
config.format = '%t %q %d %s %f %r %%';
149+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
150+
});
151+
});
152+
153+
describe('when extra whitespace is present at the start of the label', () => {
154+
it('should squash it down to a single whitespace', () => {
155+
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
156+
config.format = ' %t %q %d %s %f %r %%';
157+
expect(labelProvider.getLabel(fqi)).to.eq(` ${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
158+
});
159+
});
160+
161+
describe('when extra whitespace is present at the end of the label', () => {
162+
it('should squash it down to a single whitespace', () => {
163+
const fqi = createMockRemoteQueryInfo({ resultCount: 0, repositoryCount: 2 });
164+
config.format = '%t %q %d %s %f %r %% ';
165+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql % `);
142166
});
143167
});
144168

0 commit comments

Comments
 (0)