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

openTextDocument resolves but returns undefined for files larger than about 4MB #43861

Closed
StephenWeatherford opened this issue Feb 16, 2018 · 6 comments
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@StephenWeatherford
Copy link

StephenWeatherford commented Feb 16, 2018

  • VSCode Version: 1.20.0 (ia32)
  • OS Version: win64

Steps to Reproduce:

  1. Pass openTextDocument a file path to a text file on disk larger than 4MB
    const document = await vscode.workspace.openTextDocument(localFilePath);
  2. The resolved value of the promise will be undefined
  3. EXPECTED: The signature of the method does not include a possible undefined value, therefore it shouldn't return undefined. Here's the relevant code:
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
                                ...
				return uriPromise.then(uri => {
					return extHostDocuments.ensureDocumentData(uri).then(() => {
						const data = extHostDocuments.getDocumentData(uri);
						return data && data.document;  <<<<<<<<<<<
					});
				});
			},

NOTE: You can see this in my extension by following these steps, if you have an Azure subscription:

  1. Install https://github.com/Microsoft/vscode-azurestorage/releases/tag/V0.2.0
  2. In "Azure Storage" tree, browse to a text blob that's larger than 4MB
  3. Click it
  4. Extension will download and try to open it
    !) the download succeeds, but the open fails
  5. If you click on the link to the file in the Output pane, the file gets opened properly
@kevcunnane
Copy link

I am having this exact same problem - I have saved a file to disk that's over 50MB and then want to open and show the file. The issue is that in mainThreadDocumentsAndEditors._updateState it doesn't call onDidStateChange for large files. Hence the mainThreadDocument manager never gets the notification, and returns undefined.

This seems inconsistent - this works with File -> Open, but programmatically fails when an extension tries to do the same thing. A workaround would be a single "open and show" command that doesn't register the file as usable by language services, but guarantees it'll open.

Repro of code that will fail with large file:

            let uri = vscode.Uri.file(filePath);
            vscode.workspace.openTextDocument(uri).then((doc: vscode.TextDocument) => {
                // Show open document and set focus
                vscode.window.showTextDocument(doc, 1, false).then(undefined, (error: any) => {
                    vscode.window.showErrorMessage(error);
                });
            }, (error: any) => {
                vscode.window.showErrorMessage(error);
            });

@alexdima alexdima added the api label Feb 26, 2018
@jrieken jrieken added the bug Issue identified by VS Code Team member as probable bug label Feb 26, 2018
@jrieken jrieken added this to the February 2018 milestone Feb 26, 2018
@jrieken
Copy link
Member

jrieken commented Feb 26, 2018

Yeah, we should probably reject the promise... This challenge is that we technically support opening this (and do so) but we don't sync it to the extension host.

@jrieken
Copy link
Member

jrieken commented Feb 26, 2018

command that doesn't register the file as usable by language services, but guarantees it'll open.

That actually could work with the vscode.open-command or this overload (didn't test that): export function showTextDocument(uri: Uri, options?: TextDocumentShowOptions): Thenable<TextEditor>; (update: tested that ;-))

@jrieken
Copy link
Member

jrieken commented Feb 28, 2018

@StephenWeatherford I have pushed a change that rejects the returned promises with proper error message. We are a bit confused about the 4MB limit you have mentioned because since a few months the limit is 50MB. Where does that number come from?

In order to open very large files from an extensions you can use the vscode.open-command. This is a snippet that opens a huge file for me (>350MB).

    vscode.commands.registerCommand('extension.sayHello', () => {
        return vscode.commands.executeCommand(
           'vscode.open', 
           vscode.Uri.file('/Users/jrieken/Code/_samples/ConsoleAppDnx/large2.txt')
       );
    })

@tsalinger
Copy link
Contributor

I can verify that the error message shows.
However, the file size limit is actually 20MB by accident.
Will open a new issue for this.

@kevcunnane
Copy link

Just as an FYI, the workaround to call the vscode.open command worked great. I'm unblocked now, appreciate you helping me understand how to get this going.

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants