Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode API registerTextDocumentContentProvider for binary files #53121

Closed
TomasHubelbauer opened this issue Jun 27, 2018 · 8 comments
Closed
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s)

Comments

@TomasHubelbauer
Copy link
Contributor

I have a question, so I asked it on StackOverflow: https://stackoverflow.com/q/50803834/2715716

But I have received no answer. I can see not a lot of VS Code questions get answered on SO whereas they do get answered when asked on GH. I think unless this changes and the VS Code questions receive the same level or attention as the GH ones, people who don't respect the request will just keep asking on GH and people who are respectful and do won't be receiving any answers. I'd like to receive an answer to mine so regrettably I feel the need to reask it here.

I'd like to offer an option to display fallback content for binary files (of certain extensions) in VS Code.

I've inspected the workspace.onDidOpenTextDocument and window.onDidChangeActiveTextEditor APIs, but neither seems to be called when opening binary files.

Is there a way to display fallback content using registerTextDocumentContentProvider (or otherwise) for binary files?

I have inspected two extensions which are sort of related for how they do it:

  • VS Code PDF extension relies on the fact that for PDFs the API methods are called
  • VS Code HexDump extension enforces using a content menu command so the API methods are probably not called

There is a related issue, but it seems to indicate this is not doable, because TextDocument cannot be made from binary files and the conversation on it is locked down causing follow up discussions to take place in new issues and information to get fragmented.

Is it possible to achieve what I have in mind?

@jrieken
Copy link
Member

jrieken commented Jun 27, 2018

I've inspected the workspace.onDidOpenTextDocument and window.onDidChangeActiveTextEditor APIs, but neither seems to be called when opening binary files.

Is there a way to display fallback content using registerTextDocumentContentProvider (or otherwise) for binary files?

That's why these types all carry Text in their names, TextEditor, TextDocument, etc. They can only handle textual, not binary data ;-)

@jrieken
Copy link
Member

jrieken commented Jun 27, 2018

/duplicate of #12176

@vscodebot vscodebot bot added the *duplicate Issue identified as a duplicate of another issue(s) label Jun 27, 2018
@vscodebot
Copy link

vscodebot bot commented Jun 27, 2018

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Jun 27, 2018
@TomasHubelbauer
Copy link
Contributor Author

They also work for PDFs as evidenced by the PDF extension…

@lochbrunner
Copy link

@jrieken What about that usecase: Someone wants to use a bytecode compiled library (For instance *.class files for java or *.dll for c# in windows). Then he probably wants to see the declarations of classes, functions, ... exported by that library as it would be available as source code.
What is the approach to archive that?

@jrieken
Copy link
Member

jrieken commented Jul 16, 2018

As long as the output is textual everything is good and you can use the TextDocumentContentProvider. This is how omnisharp does it for c#-dll-files: https://github.com/OmniSharp/omnisharp-vscode/blob/94d07b6fc174bbef3a28a80918bf75507c3c6bdc/src/features/definitionMetadataDocumentProvider.ts

@TomasHubelbauer
Copy link
Contributor Author

I have OmniSharp installed and clicking on a DLL file in the Explorer pane will bring up the usual "binary file" screen. Does OmniSharp only support displaying metadata from DLL files programatically (say using Go To Definition) or is it possible to get that behavior upon clicking an Explorer pane tree item manually?

I think it is not possible, from what I remember, the provider will only fire for what VS Code considers to be actual text files and for some reason PDFs (bug in text file detection algorithm? PDFs are texty), but no other binary files.

Can you please confirm my understanding that the provider alone won't add support for click-to-open on binary files?

@jrieken
Copy link
Member

jrieken commented Jul 16, 2018

Can you please confirm my understanding that the provider alone won't add support for click-to-open on binary files?

Confirmed - the is no support for custom editors or content transformers when opening a file

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants