Skip to content

Commit 39a1524

Browse files
committed
Ask user to open sarif file externally when too large
Use the same mechanism that we are using for log files to open large sarif files. This is because the extension is not capable of opening large (>50MB) files due to vscode restrictions.
1 parent 081aab7 commit 39a1524

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

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

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,32 +221,7 @@ export class QueryHistoryManager {
221221

222222
async handleShowQueryLog(queryHistoryItem: CompletedQuery) {
223223
if (queryHistoryItem.logFileLocation) {
224-
const uri = vscode.Uri.file(queryHistoryItem.logFileLocation);
225-
try {
226-
await vscode.window.showTextDocument(uri);
227-
} catch (e) {
228-
if (e.message.includes('Files above 50MB cannot be synchronized with extensions')) {
229-
const res = await helpers.showBinaryChoiceDialog(
230-
`VS Code does not allow extensions to open files >50MB. This file
231-
exceeds that limit. Do you want to open it outside of VS Code?
232-
233-
You can also try manually opening it inside VS Code by selecting
234-
the file in the file explorer and dragging it into the workspace.`
235-
);
236-
if (res) {
237-
try {
238-
await vscode.commands.executeCommand('revealFileInOS', uri);
239-
} catch (e) {
240-
helpers.showAndLogErrorMessage(e.message);
241-
}
242-
}
243-
} else {
244-
helpers.showAndLogErrorMessage(`Could not open log file ${queryHistoryItem.logFileLocation}`);
245-
logger.log(e.message);
246-
logger.log(e.stack);
247-
}
248-
249-
}
224+
await this.tryOpenExternalFile(queryHistoryItem.logFileLocation);
250225
} else {
251226
helpers.showAndLogWarningMessage('No log file available');
252227
}
@@ -271,8 +246,9 @@ the file in the file explorer and dragging it into the workspace.`
271246
try {
272247
const hasInterpretedResults = await queryHistoryItem.query.canHaveInterpretedResults();
273248
if (hasInterpretedResults) {
274-
const textDocument = await vscode.workspace.openTextDocument(vscode.Uri.file(queryHistoryItem.query.resultsPaths.interpretedResultsPath));
275-
await vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One);
249+
await this.tryOpenExternalFile(
250+
queryHistoryItem.query.resultsPaths.interpretedResultsPath
251+
);
276252
}
277253
else {
278254
const label = queryHistoryItem.getLabel();
@@ -368,4 +344,37 @@ the file in the file explorer and dragging it into the workspace.`
368344
}
369345
}
370346
}
347+
348+
private async tryOpenExternalFile(fileLocation: string) {
349+
const uri = vscode.Uri.file(fileLocation);
350+
try {
351+
await vscode.window.showTextDocument(uri);
352+
} catch (e) {
353+
if (
354+
e.message.includes(
355+
"Files above 50MB cannot be synchronized with extensions"
356+
) ||
357+
e.message.includes("too large to open")
358+
) {
359+
const res = await helpers.showBinaryChoiceDialog(
360+
`VS Code does not allow extensions to open files >50MB. This file
361+
exceeds that limit. Do you want to open it outside of VS Code?
362+
363+
You can also try manually opening it inside VS Code by selecting
364+
the file in the file explorer and dragging it into the workspace.`
365+
);
366+
if (res) {
367+
try {
368+
await vscode.commands.executeCommand("revealFileInOS", uri);
369+
} catch (e) {
370+
helpers.showAndLogErrorMessage(e.message);
371+
}
372+
}
373+
} else {
374+
helpers.showAndLogErrorMessage(`Could not open file ${fileLocation}`);
375+
logger.log(e.message);
376+
logger.log(e.stack);
377+
}
378+
}
379+
}
371380
}

0 commit comments

Comments
 (0)