Skip to content

Commit ab3822d

Browse files
authored
Use SARIF viewer extension for analysis results (#1125)
1 parent 69120e0 commit ab3822d

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

extensions/ql-vscode/src/pure/interface-types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ export type FromRemoteQueriesMessage =
378378
| OpenFileMsg
379379
| OpenVirtualFileMsg
380380
| RemoteQueryDownloadAnalysisResultsMessage
381-
| RemoteQueryDownloadAllAnalysesResultsMessage;
381+
| RemoteQueryDownloadAllAnalysesResultsMessage
382+
| RemoteQueryViewAnalysisResultsMessage;
382383

383384
export type ToRemoteQueriesMessage =
384385
| SetRemoteQueryResultMessage
@@ -412,3 +413,8 @@ export interface RemoteQueryDownloadAllAnalysesResultsMessage {
412413
t: 'remoteQueryDownloadAllAnalysesResults';
413414
analysisSummaries: AnalysisSummary[];
414415
}
416+
417+
export interface RemoteQueryViewAnalysisResultsMessage {
418+
t: 'remoteQueryViewAnalysisResults';
419+
analysisSummary: AnalysisSummary
420+
}

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
ViewColumn,
66
Uri,
77
workspace,
8+
extensions,
9+
commands,
810
} from 'vscode';
911
import * as path from 'path';
1012

@@ -14,6 +16,7 @@ import {
1416
FromRemoteQueriesMessage,
1517
RemoteQueryDownloadAnalysisResultsMessage,
1618
RemoteQueryDownloadAllAnalysesResultsMessage,
19+
RemoteQueryViewAnalysisResultsMessage,
1720
} from '../pure/interface-types';
1821
import { Logger } from '../logging';
1922
import { getHtmlForWebview } from '../interface-utils';
@@ -199,6 +202,9 @@ export class RemoteQueriesInterfaceManager {
199202
case 'remoteQueryDownloadAllAnalysesResults':
200203
await this.downloadAllAnalysesResults(msg);
201204
break;
205+
case 'remoteQueryViewAnalysisResults':
206+
await this.viewAnalysisResults(msg);
207+
break;
202208
default:
203209
assertNever(msg);
204210
}
@@ -217,6 +223,28 @@ export class RemoteQueriesInterfaceManager {
217223
results => this.setAnalysisResults(results));
218224
}
219225

226+
private async viewAnalysisResults(msg: RemoteQueryViewAnalysisResultsMessage): Promise<void> {
227+
const downloadLink = msg.analysisSummary.downloadLink;
228+
const filePath = path.join(tmpDir.name, downloadLink.id, downloadLink.innerFilePath || '');
229+
230+
const sarifViewerExtensionId = 'MS-SarifVSCode.sarif-viewer';
231+
232+
const sarifExt = extensions.getExtension(sarifViewerExtensionId);
233+
if (!sarifExt) {
234+
// Ask the user if they want to install the extension to view the results.
235+
void commands.executeCommand('workbench.extensions.installExtension', sarifViewerExtensionId);
236+
return;
237+
}
238+
239+
if (!sarifExt.isActive) {
240+
await sarifExt.activate();
241+
}
242+
243+
await sarifExt.exports.openLogs([
244+
Uri.file(filePath),
245+
]);
246+
}
247+
220248
public async setAnalysisResults(analysesResults: AnalysisResults[]): Promise<void> {
221249
if (this.panel?.active) {
222250
await this.postMessage({

extensions/ql-vscode/src/remote-queries/view/RemoteQueries.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import DownloadButton from './DownloadButton';
1717
import { AnalysisResults } from '../shared/analysis-result';
1818
import DownloadSpinner from './DownloadSpinner';
1919
import CollapsibleItem from './CollapsibleItem';
20+
import { FileSymlinkFileIcon } from '@primer/octicons-react';
2021

2122
const numOfReposInContractedMode = 10;
2223

@@ -47,6 +48,13 @@ const downloadAllAnalysesResults = (query: RemoteQueryResult) => {
4748
});
4849
};
4950

51+
const viewAnalysisResults = (analysisSummary: AnalysisSummary) => {
52+
vscode.postMessage({
53+
t: 'remoteQueryViewAnalysisResults',
54+
analysisSummary
55+
});
56+
};
57+
5058
const openQueryFile = (queryResult: RemoteQueryResult) => {
5159
vscode.postMessage({
5260
t: 'openFile',
@@ -110,7 +118,7 @@ const SummaryTitleNoResults = () => (
110118
</div>
111119
);
112120

113-
const SummaryItemDownload = ({
121+
const SummaryItemDownloadAndView = ({
114122
analysisSummary,
115123
analysisResults
116124
}: {
@@ -130,7 +138,13 @@ const SummaryItemDownload = ({
130138
</>;
131139
}
132140

133-
return (<></>);
141+
return <>
142+
<HorizontalSpace size={2} />
143+
<a className="vscode-codeql__analysis-result-file-link"
144+
onClick={() => viewAnalysisResults(analysisSummary)} >
145+
<FileSymlinkFileIcon size={16} />
146+
</a>
147+
</>;
134148
};
135149

136150
const SummaryItem = ({
@@ -145,7 +159,7 @@ const SummaryItem = ({
145159
<span className="vscode-codeql__analysis-item">{analysisSummary.nwo}</span>
146160
<span className="vscode-codeql__analysis-item"><Badge text={analysisSummary.resultCount.toString()} /></span>
147161
<span className="vscode-codeql__analysis-item">
148-
<SummaryItemDownload
162+
<SummaryItemDownloadAndView
149163
analysisSummary={analysisSummary}
150164
analysisResults={analysisResults} />
151165
</span>

extensions/ql-vscode/src/remote-queries/view/remoteQueries.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@
6060
padding-top: 1em;
6161
font-size: x-small;
6262
}
63+
64+
.vscode-codeql__analysis-result-file-link {
65+
vertical-align: middle;
66+
}

0 commit comments

Comments
 (0)