Skip to content

Commit 04c9f17

Browse files
committed
Get query ID for query history items (incl VariantAnalysisHistoryItem)
1 parent 60e9f55 commit 04c9f17

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ export function getRawQueryName(item: QueryHistoryInfo): string {
1717
assertNever(item);
1818
}
1919
}
20+
21+
export function getQueryId(item: QueryHistoryInfo): string {
22+
switch (item.t) {
23+
case 'local':
24+
return item.initialInfo.id;
25+
case 'remote':
26+
return item.queryId;
27+
case 'variant-analysis':
28+
return item.variantAnalysis.id.toString();
29+
default:
30+
assertNever(item);
31+
}
32+
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { commandRunner } from './commandRunner';
3131
import { ONE_HOUR_IN_MS, TWO_HOURS_IN_MS } from './pure/time';
3232
import { assertNever, getErrorMessage, getErrorStack } from './pure/helpers-pure';
3333
import { CompletedLocalQueryInfo, LocalQueryInfo } from './query-results';
34-
import { QueryHistoryInfo } from './query-history-info';
34+
import { getQueryId, QueryHistoryInfo } from './query-history-info';
3535
import { DatabaseManager } from './databases';
3636
import { registerQueryHistoryScrubber } from './query-history-scrubber';
3737
import { QueryStatus } from './query-status';
@@ -1068,19 +1068,13 @@ export class QueryHistoryManager extends DisposableObject {
10681068
queryText: encodeURIComponent(await this.getQueryText(finalSingleItem)),
10691069
});
10701070

1071-
if (finalSingleItem.t === 'variant-analysis') {
1072-
// TODO
1073-
} else {
1074-
const queryId = finalSingleItem.t === 'local'
1075-
? finalSingleItem.initialInfo.id
1076-
: finalSingleItem.queryId;
1071+
const queryId = getQueryId(finalSingleItem);
10771072

1078-
const uri = Uri.parse(
1079-
`codeql:${queryId}?${params.toString()}`, true
1080-
);
1081-
const doc = await workspace.openTextDocument(uri);
1082-
await window.showTextDocument(doc, { preview: false });
1083-
}
1073+
const uri = Uri.parse(
1074+
`codeql:${queryId}?${params.toString()}`, true
1075+
);
1076+
const doc = await workspace.openTextDocument(uri);
1077+
await window.showTextDocument(doc, { preview: false });
10841078
}
10851079

10861080
async handleViewSarifAlerts(

extensions/ql-vscode/test/pure-tests/query-history-info.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22

33
import { QueryStatus } from '../../src/query-status';
4-
import { getRawQueryName } from '../../src/query-history-info';
4+
import { getQueryId, getRawQueryName } from '../../src/query-history-info';
55
import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item';
66
import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis';
77
import { createMockLocalQueryInfo } from '../../src/vscode-tests/factories/local-queries/local-query-history-item';
@@ -40,4 +40,37 @@ describe('Query history info', () => {
4040
expect(queryName).to.equal(queryHistoryItem.variantAnalysis.query.name);
4141
});
4242
});
43+
44+
describe('getQueryId', () => {
45+
it('should get the ID for local history items', () => {
46+
const date = new Date('2022-01-01T00:00:00.000Z');
47+
const dateStr = date.toLocaleString();
48+
49+
const queryHistoryItem = createMockLocalQueryInfo(dateStr);
50+
51+
const queryId = getQueryId(queryHistoryItem);
52+
53+
expect(queryId).to.equal(queryHistoryItem.initialInfo.id);
54+
});
55+
56+
it('should get the ID for remote query history items', () => {
57+
const queryHistoryItem = createMockRemoteQueryHistoryItem({});
58+
const queryId = getQueryId(queryHistoryItem);
59+
60+
expect(queryId).to.equal(queryHistoryItem.queryId);
61+
});
62+
63+
it('should get the ID for variant analysis history items', () => {
64+
const queryHistoryItem: VariantAnalysisHistoryItem = {
65+
t: 'variant-analysis',
66+
status: QueryStatus.InProgress,
67+
completed: false,
68+
variantAnalysis: createMockVariantAnalysis()
69+
};
70+
71+
const queryId = getQueryId(queryHistoryItem);
72+
73+
expect(queryId).to.equal(queryHistoryItem.variantAnalysis.id.toString());
74+
});
75+
});
4376
});

0 commit comments

Comments
 (0)