Skip to content

Commit 82b6549

Browse files
committed
[mlir:vscode] Add support for loading big bytecode files
VSCode doesn't let our extension manage files >50mb. This commit adds a proper diagnostic in this case, and also gives the user an option to open as a temporary .mlir file instead. Differential Revision: https://reviews.llvm.org/D133242
1 parent 7f57c97 commit 82b6549

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

mlir/utils/vscode/src/MLIR/bytecodeProvider.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,40 @@ class BytecodeFS implements vscode.FileSystemProvider {
7070
throw new Error(
7171
'Failed to activate mlir language server to read bytecode');
7272
}
73+
7374
// Ask the client to do the conversion.
74-
let convertParams: ConvertBytecodeParams = {uri : uri.toString()};
75+
let result: ConvertBytecodeResult;
7576
try {
76-
const result: ConvertBytecodeResult =
77-
await client.sendRequest('mlir/convertFromBytecode', convertParams);
78-
return new TextEncoder().encode(result.output);
77+
let params: ConvertBytecodeParams = {uri : uri.toString()};
78+
result = await client.sendRequest('mlir/convertFromBytecode', params);
7979
} catch (e) {
8080
vscode.window.showErrorMessage(e.message);
8181
throw new Error(`Failed to read bytecode file: ${e}`);
8282
}
83+
let resultBuffer = new TextEncoder().encode(result.output);
84+
85+
// NOTE: VSCode does not allow for extensions to manage files above 50mb.
86+
// Detect that here and if our result is too large for us to manage, alert
87+
// the user and open it as a new temporary .mlir file.
88+
if (resultBuffer.length > (50 * 1024 * 1024)) {
89+
const openAsTempInstead: vscode.MessageItem = {
90+
title : 'Open as temporary .mlir instead',
91+
};
92+
const message: string = `Failed to open bytecode file "${
93+
uri.toString()}". Cannot edit converted bytecode files larger than 50MB.`;
94+
const errorResult: vscode.MessageItem|undefined =
95+
await vscode.window.showErrorMessage(message, openAsTempInstead);
96+
if (errorResult === openAsTempInstead) {
97+
let tempFile = await vscode.workspace.openTextDocument({
98+
language : 'mlir',
99+
content : result.output,
100+
});
101+
await vscode.window.showTextDocument(tempFile);
102+
}
103+
throw new Error(message);
104+
}
105+
106+
return resultBuffer;
83107
}
84108

85109
/*

0 commit comments

Comments
 (0)