Can I open a binary file as a text document? #2638
-
I have .spv files that contain statements from a binary intermediate language called SPIR-V (you can think about it like IL code, or Java bytecode). Can I create an extension that opens a read-only text editor with language features, that contains the assembly-like text representation of the statements when I open those files? Since these are generated files, I don't ever want to edit them. I can't use the regular language features, the custom text editor, or the Language Server Protocol directly on the .spv files, since they are binary. I have some workarounds, but they are not perfect. I could create a command that either generates and opens a text-based file on disk or opens a virtual document. However, this means that the user has to manually trigger this after she/he opens the binary document. I could create a custom editor and show the assembly in the webview, but I'd lose all language features, like syntax highlight, go to definition, etc. I could create an empty custom editor, and when it's opened, I also open a virtual document, and close the custom editor. However, this is a hack, and also, the custom editor is still showing up. Is there a valid way to open a binary file as a text document? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can refer to vscode-extension-samples/custom-editor-sample. It includes:
|
Beta Was this translation helpful? Give feedback.
-
Hi @racz16 , Right now, your scenario is not supported. Both Custom Editors API ( You could use Monaco Editor or ShikiJS in order to have syntax highlighting capabilities, but language features like Got To Definition or Code Completion won't be available out of the box. If this doesn't fit your needs, I would suggest you to open a feature request in the VS Code repo (https://github.com/microsoft/vscode/issues) so the VS Code team could take a look. Hope this helps |
Beta Was this translation helpful? Give feedback.
Hi @racz16 ,
Right now, your scenario is not supported. Both Custom Editors API (
CustomTextEditorProvider
andCustomEditorProvider
) are intended for read/write editors, which means they intend to give the extension author a custom view to display/edit the file. That's why both APIs require the extension to provide aWebView
as the container of its file.You could use Monaco Editor or ShikiJS in order to have syntax highlighting capabilities, but language features like Got To Definition or Code Completion won't be available out of the box.
If this doesn't fit your needs, I would suggest you to open a feature request in the VS Code repo (https://github.com/microsoft/vscode/issues) so the VS…