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

Expose VS Code extension API for telling text and binary files apart the same way VS Code does #58933

Closed
TomasHubelbauer opened this issue Sep 19, 2018 · 6 comments
Assignees
Labels
api *duplicate Issue identified as a duplicate of another issue(s)

Comments

@TomasHubelbauer
Copy link
Contributor

I have an extension which needs to index the workspace files and do additional processing for text file. The way I currently do it is to do a search for workspace.findFiles('**/*.*') and try workspace.openTextDocument on all of the results. If an exception is caught, I consider that to be a binary file and skip it. If not, I continue with processing the file.

This works, but it causes the "VS Code Marketplace has extension to help with the .random file type" kinds messages to appear for files the user has not opened (because I don't do window.showDocument).

How can I keep indexing the workspace without causing these messages to appear? And it that is not possible, could an extension API for this detection be provided instead?

I would like to avoid trying to reimplement that detection myself as it's important for the logic to be and stay the same as VS Code, otherwise a failure to keep up with VS Code's changes to this logic will return to causing these messages to appear.

@jrieken
Copy link
Member

jrieken commented Sep 19, 2018

First what you need is #48034 which is about a low level file read/write API. Using openTextDocument triggers all kind of things that you don't want. Triggering the language detection is tracked here #11838.

I have an extension which needs to index the workspace files and do additional processing for text file

Given the things above indexing shouldn't be done in the extension host as it will likely saturate the process and prevent other extension logic from executing.

@jrieken
Copy link
Member

jrieken commented Sep 19, 2018

closing as double dupe

@jrieken jrieken added the *duplicate Issue identified as a duplicate of another issue(s) label Sep 19, 2018
@vscodebot
Copy link

vscodebot bot commented Sep 19, 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 Sep 19, 2018
@TomasHubelbauer
Copy link
Contributor Author

I don't understand how the language detection issue relates to this problem, sorry.

For the read/write access API, I know about that issue and I will have great use for it once it lands, but I don't understand how is that supposed to tell me what VS Code considers to be a binary file and what it considers to be a text file either.

I am trying to find a logic which for a given URI will determine if VS Code will be able to display that file or not. Whether we're talking about a file URI or a virtual FS URI, that doesn't change it, VS Code still does some decision on whether it considers that buffer to be textual or not and according to it either displays the editor or displays the "Cannot open binary" message.

This can stay closed, because I have found a solution for this particular extension I am working on, but in general I think it would still be useful. At the very least this is out-of-scope not a duplicate.

@jrieken
Copy link
Member

jrieken commented Sep 20, 2018

I don't understand how the language detection issue relates to this problem, sorry.

Language detection includes detecting if a file is binary or textual.

@TomasHubelbauer
Copy link
Contributor Author

I see, but from reading that issue I don't see it mentioned. Would that information be exposed to the extension API or would we get either langues is X or language is unknown only?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api *duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

2 participants