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.window.activeTextEditor is undefined for files larger then 5MB #32118

Closed
GreenRover opened this issue Aug 8, 2017 · 9 comments
Closed
Assignees
Labels
api under-discussion Issue is under discussion for relevance, priority, approach
Milestone

Comments

@GreenRover
Copy link

I wrote an Visual Studio Code extension. Based on this example: https://github.com/Microsoft/vscode-extension-samples/tree/master/previewhtml-sample

    var editor = vscode.window.activeTextEditor;
    if (!editor) {
        console.log("No open text editor");
    }

This works fine if i open a 2MB File. But not if the file is 5MB or larger.

But if i copy (CTRL+C,CTRL+V) a 10MB into a new editor it will work and is prety fast. Has anyone an idea what kind of limitation this is?

@vscodebot vscodebot bot added the api label Aug 8, 2017
@alexdima
Copy link
Member

alexdima commented Aug 8, 2017

When we open a file (and only when opening it), we classify it:

  • if the file is over 30MB or over 300k lines, we consider it to be a very large file and proceed to turn off very many features, including tokenization, word wrapping, indent guides, anything that would consume additional memory, etc.

  • if the file is over 5MB, we consider it to be a large file and we actively hide it from the extension host: this reduces the feature set for such files (e.g. go to definition, find all references will not work, etc.), but leaves some basics working: tokenization, link detection, word suggestions, etc.

  • otherwise, the file is considered to be a normal file and suffers no restrictions.

We have implemented these graceful degradation limits based on our experience in dealing with large files. i.e. we have found very many language servers struggle with file sizes above 5MB so we decided to introduce a limit at the extension host layer.

This classification can be circumvented by editing a file. i.e. start with a small file, and then use ctrl+c ctrl+v to increase it to a size above 5 MB, etc. The above classification is made only when the buffer is created.

@alexdima alexdima added the *as-designed Described behavior is as designed label Aug 8, 2017
@GreenRover
Copy link
Author

GreenRover commented Aug 8, 2017

In case of a LARGE file: Is it possible for an extension to get whole file contenst?
Here a code sample:
https://github.com/GreenRover/hibernate-log-analyser/blob/master/src/extension.ts

@alexdima
Copy link
Member

alexdima commented Aug 8, 2017

No, I'm sorry, opened files over 5MB are currently completely hidden from the extension host.

I believe we took this decision at a time before we had such a rich extension ecosystem and it is perhaps time to revisit it. i.e. we should consider removing this restriction and push the responsibility of dealing in a smart way with large files down to the extensions themselves.

@alexdima alexdima added this to the On Deck milestone Aug 8, 2017
@GreenRover
Copy link
Author

Hi can you tell me the variable where the 5MB is stored in to let me hack my local vs code?
Or is there an way to just get the path of the file that is currently in focus?

@alexdima
Copy link
Member

@GreenRover Here's the location: https://github.com/Microsoft/vscode/blob/88be6de0b7ac0ac787a6ea9c472c1d7b2ca2d380/src/vs/editor/common/model/textModel.ts#L33

In the built workbench.main.js you could look for MODEL_SYNC_LIMIT

@GreenRover
Copy link
Author

Hi a changed this value in workbench.main.js and tryed to open a 21MB file but it failed.
Are there other limitations?

@alexdima alexdima added under-discussion Issue is under discussion for relevance, priority, approach and removed *as-designed Described behavior is as designed labels Aug 19, 2017
@alexdima
Copy link
Member

alexdima commented Aug 19, 2017

No, that single constant is responsible for the limitation.

@jrieken I suggest I simply increase the constant. Did we ever document the limitation? i.e. extensions will begin seeing larger files after this change, I hope nobody built their extensions on the constraints that they don't need to deal with files larger than 5MB.

@jrieken
Copy link
Member

jrieken commented Aug 21, 2017

I suggest I simply increase the constant. Did we ever document the limitation?

I don't think so

@alexdima
Copy link
Member

I increased the limit to 50MB

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

3 participants