[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
This commit is contained in:
River Riddle 2022-09-02 18:52:43 -07:00
parent 7f57c97d30
commit 82b6549654
1 changed files with 28 additions and 4 deletions

View File

@ -70,16 +70,40 @@ class BytecodeFS implements vscode.FileSystemProvider {
throw new Error(
'Failed to activate mlir language server to read bytecode');
}
// Ask the client to do the conversion.
let convertParams: ConvertBytecodeParams = {uri : uri.toString()};
let result: ConvertBytecodeResult;
try {
const result: ConvertBytecodeResult =
await client.sendRequest('mlir/convertFromBytecode', convertParams);
return new TextEncoder().encode(result.output);
let params: ConvertBytecodeParams = {uri : uri.toString()};
result = await client.sendRequest('mlir/convertFromBytecode', params);
} catch (e) {
vscode.window.showErrorMessage(e.message);
throw new Error(`Failed to read bytecode file: ${e}`);
}
let resultBuffer = new TextEncoder().encode(result.output);
// NOTE: VSCode does not allow for extensions to manage files above 50mb.
// Detect that here and if our result is too large for us to manage, alert
// the user and open it as a new temporary .mlir file.
if (resultBuffer.length > (50 * 1024 * 1024)) {
const openAsTempInstead: vscode.MessageItem = {
title : 'Open as temporary .mlir instead',
};
const message: string = `Failed to open bytecode file "${
uri.toString()}". Cannot edit converted bytecode files larger than 50MB.`;
const errorResult: vscode.MessageItem|undefined =
await vscode.window.showErrorMessage(message, openAsTempInstead);
if (errorResult === openAsTempInstead) {
let tempFile = await vscode.workspace.openTextDocument({
language : 'mlir',
content : result.output,
});
await vscode.window.showTextDocument(tempFile);
}
throw new Error(message);
}
return resultBuffer;
}
/*