vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Support large documents in extension host

Open emackey opened this issue 8 years ago • 31 comments

  • VSCode Version: 1.14.1
  • OS Version: Windows 7 and Windows 10, likely all OSes

When editing documents with very long lines, such as lines containing data-URIs, the property vscode.window.activeTextEditor will be undefined when it should be defined.

Steps to reproduce:

  1. Create a new (blank) VSCode extension, and add this command to extension.ts:
'use strict';
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('bigDocTest.runDocTest', () => {

        let hasActiveTextEditor = (vscode.window.activeTextEditor !== undefined);

        if (hasActiveTextEditor) {
            vscode.window.showInformationMessage('Success, activeTextEditor is defined.');
        } else {
            vscode.window.showErrorMessage('Oops, activeTextEditor is not defined.');
        }
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {
}
  1. Launch this extension, load any normal text file, and run this command, you see the "Success, activeTextEditor is defined" information message appear.

  2. But, try loading a file with a very long line contained inside it, such as this one: MetalRoughSpheres.gltf. This file has long lines due to the use of embedded data URIs in the file. If you run the above sample extension while editing this file, you see "Oops, activeTextEditor is not defined."

This makes it difficult for VSCode extensions to work with such files. I'm the lead dev of the GLTF extension for VSCode, and this prevents my extension from running on GLTF files that embed large images as data URIs.

emackey avatar Jul 19 '17 22:07 emackey

Yes, we unfortunately have to do that because very large documents (those with long lines or many lines) are very likely to make the extension host choke and stall. The current limit is at 5MB. If a file exceeds that we don't sync it over to the extension host but only offer editing capabilities.

jrieken avatar Jul 20 '17 08:07 jrieken

Thanks for replying. Does the user have any way to configure the 5MB limit to be larger? Could this issue be turned into an enhancement request for user-configurable max line length for extensions?

The current limit is particularly painful for extensions whose sole purpose is to augment editing of such files.

emackey avatar Jul 20 '17 17:07 emackey

The limit isn't configurable and it is somewhat arbitrary, tho before increasing it we should check how the extension host behaves with large files. Obviously this is more complicated then just having a check for one file, because many little files can also be a problem...

jrieken avatar Jul 20 '17 18:07 jrieken

Great, thanks @jrieken. GitHub isn't showing me a reopen button, can this be reopened?

emackey avatar Jul 20 '17 19:07 emackey

I am working on a extension that must work on large xml files which routinely are over 5MB. I just ran into this issue :-(. Making this configurable by the extension or offering an alternative scheme for commands to to still work would be helpful.

schaveyt avatar Jul 20 '17 19:07 schaveyt

re https://github.com/Microsoft/vscode/issues/31078#issuecomment-316801062 - forgot to press reopen...

jrieken avatar Jul 21 '17 07:07 jrieken

Anyone happen to know where this limit is specified in the source code?

emackey avatar Jul 21 '17 14:07 emackey

Perhaps a very limited, restricted api. IMHO, the primary thing that I and other should be able to get by with is:

Request the Uri and LineNumber of the Cursor for the active document.

The intent is for the vscode to tell the extension author, "Hey here is the what the user is up to, but I am not parsing that big file for you..have fun :-)"

window.activeTextEditorLocation(): Location | undefinded

Example usage:

'use strict';
import * as vscode from 'vscode';
import {MyCustomExtensionHelper} from './MyCustomExtensionHelper'

export function activate(context: vscode.ExtensionContext) {

    let disposableWordCounts = vscode.commands.registerCommand('bigDocTest.runDocTest', () => {
        let activeTextEditorLocation = (vscode.window.activeTextEditorLocation !== undefined);

        if (!activeTextEditorLocation) {
            vscode.window.showErrorMessage('No document is open.');
        }

        const helper = new MyCustomerExtensionHelper();
        helper.reportWordCount(activeTextEditorLocation.uri)   
    });

    let textEditorCommand = vscode.commands.registerTextEditorCommand('bigDocTest.customMenuItem1', () => {
        let activeTextEditorLocation = (vscode.window.activeTextEditorLocation !== undefined);

        if (!activeTextEditorLocation) {
            vscode.window.showErrorMessage('No document is open.');
        }

        const helper = new MyCustomerExtensionHelper();
        const activeWord = helper.getWordTheUserCursorIsOne(activeTextEditorLocation);
        helper.findAllReferences(activeWord);
    });

    context.subscriptions.push(disposableWordCounts, textEditorCommand);
}

export function deactivate() {
}

This one little function would enable a fairly wide variety of use cases.

  • This would fix my ReferenceProviders
  • This would fix my DefinitionProviders
  • This would fix my TextEditorCommand handlers
  • This would fix my Command handlers

schaveyt avatar Jul 29 '17 15:07 schaveyt

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodebot[bot] avatar Jan 18 '20 12:01 vscodebot[bot]

It would be great for the user to be able to configure it at least. I work with log files of max 200MB using Visual Studio Code and since there is no native filtering using line or regex (include/exclude), I can't filter the log file through third-party extension either...

@Leonid-Kokhnovych-Rivian please see my extension https://github.com/mbehr1/vsc-lfs. It's really hackish but might be useful for your use-case especially if you want to filter a lot of content anyhow (see setting vsc-lfs.replacements ).

mbehr1 avatar Dec 23 '20 09:12 mbehr1

Solving this would be of great help!

digitalAssetStore avatar Jun 16 '21 10:06 digitalAssetStore

Hello, any updates on this issue?

lucasrmendonca avatar Jan 30 '23 20:01 lucasrmendonca

@emackey, this is controlled by the _MODEL_SYNC_LIMIT property of the TextModel class defined here: https://github.com/microsoft/vscode/blob/ecf479e662923a158c04ab58a835549a312442bf/src/vs/editor/common/model/textModel.ts#L176

On my system I was able to increase this limit by patching the workbench.desktop.main.js file. However, note that this might cause vscode to display a warning that the installation is corrupt. Still, this worked for me.

Here's the command I used (not that I recommend doing it):

$ sudo sed -iE 's/\._MODEL_SYNC_LIMIT=50\*1024\*1024,/._MODEL_SYNC_LIMIT=500*1024*1024,/g' /usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js

zb3 avatar Feb 18 '23 17:02 zb3

Any progress on this? I want to use "Text Power Tools" (https://github.com/Microsoft/vscode/issues/31078) to filter large LOG files (size of them is out of my control) - and not having this function makes me to use Powershell to filter them before hand instead - which is a petty - as I rather use it inside vscode - when can we expect a fix for this?

ThaDaVos avatar Oct 12 '23 09:10 ThaDaVos

Just stumbled into this issue myself. I have an extension that gives me emacs style keybindings. Of course, since it's an extension, whenever I open a file larger than 50MiB, they don't work. This makes me unable to navigate large files with the keyboard (even through the cursor keys).

An option to configure _MODEL_SYNC_LIMIT would go a long way. I'd see about implementing it myself, if Microsoft would be willing to merge it.

RossBrunton avatar Oct 12 '23 11:10 RossBrunton

It's been 5 years now with this issue. Can we please get the possibility to edit the limit in the config. The default can stay the same, so most people wouldn't even notice.

oaldrian avatar Dec 04 '23 09:12 oaldrian

It would be very useful to at least have find and replace for very large lines. Currently i have to use grep

ada2k avatar Dec 12 '23 22:12 ada2k

The issue is still in place, and it would really be nice to make that limit configurable and let users decide whether they are ok with excessive CPU/MEM usage.

yachnyymaxim avatar May 27 '24 15:05 yachnyymaxim

6 years, now

It's been 5 years now with this issue. Can we please get the possibility to edit the limit in the config. The default can stay the same, so most people wouldn't even notice.

ehartford avatar Nov 21 '24 14:11 ehartford

The error shown for some extensions is unintuitive. For example for the Bookmarks extension with a large file, the error message is

Open a file first to toggle bookmarks

It would be very helpful if the message instead was

The Bookmark extension is disabled for this file which is larger than 5 MB

cmcqueen avatar Dec 04 '24 09:12 cmcqueen

Hi everyone,

I found an extension that solves this issue! The extension is called “Filter Line". While it has a limitation on large files, they provide a workaround.

Here’s the solution mentioned in their README: Image

Essentially, you need to create a file named filterline in the same directory as the file you want to filter. Then, use the tool as if you were working with the logs file. The filterline file will contain the filtered results.

I hope this helps!

Regards

QudeCode avatar Dec 12 '24 10:12 QudeCode

Any ETA on the issue itself?

needed for this extensions https://github.com/mfoulks3200/har-analyzer

DenisBalan avatar Jan 02 '25 08:01 DenisBalan

@QudeCode You can actually use this convenient method.

Image

BlazingForests avatar Jan 21 '25 06:01 BlazingForests

Allowing certain extensions to work in large file mode would be nice.
Here is a good example: https://github.com/mguellsegarra/highlight-on-copy. This extension can not impact performance since it only changes the background color. But now it can not work (even worse, it prevents the original copy function because it registers ctrl+c hotkey). I think it would be nice to add a manifest option like allowLargeFile for developers to declare their extension does not relate to the file size.

RichardLuo0 avatar Feb 25 '25 18:02 RichardLuo0

I think a good portion of users affected by this limitation, are people who wants to use VSCode as a log file inspection tool. Extensions like Text Power Tools add a layer of very useful text filtering and manipulation commands.

However, VSCode is not an appropriate tool for the task, and that's by design. It needs to pass context to a secondary process (an extension host), which is generally a great idea but not ideal nor performant enough when one is inspecting a 2 million lines file that weights 800 MB.

What we'd actually need instead is a proper tool for the task. Does anyone reading this issue know of one such tool that we could use as replacement for this specific use cases?

j1elo avatar May 21 '25 09:05 j1elo

I want search and replace (with regex) on arbitrarily large documents.
I don't want to have to write python code for what I should be able to search and replace. the limitation cost me an hour per day

ehartford avatar May 21 '25 14:05 ehartford

What we'd actually need instead is a proper tool for the task. Does anyone reading this issue know of one such tool that we could use as replacement for this specific use cases?

https://elpa.gnu.org/packages/vlf.html

xgdgsc avatar May 21 '25 14:05 xgdgsc

For log-files in DLT, Android syslog (and a few more) you can use my extension: https://marketplace.visualstudio.com/items?itemName=mbehr1.dlt-logs

I have an extension for „large files“ as well (https://marketplace.visualstudio.com/items?itemName=mbehr1.vsc-lfs ) using some hacks to make vscode open large files… (but it’s a hack and I guess won’t work for 800mb files). (For the dlt-logs extensions the log files can be multiple GB in size.)

Which log file format are you looking at?

Am 21.05.2025 um 11:07 schrieb Juan Navarro @.***>:

j1elo left a comment (microsoft/vscode#31078) https://github.com/microsoft/vscode/issues/31078#issuecomment-2897189334 I think a good portion of users affected by this limitation, are people who wants to use VSCode as a log file inspection tool. Extensions like Text Power Tools https://marketplace.visualstudio.com/items?itemName=qcz.text-power-tools add a layer of very useful text filtering and manipulation commands.

However, VSCode is not an appropriate tool for the task, and that's by design. It needs to pass context to a secondary process (an extension host), which is generally a great idea but not ideal nor performant enough when one is inspecting a 2 million lines file that weights 800 MB.

What we'd actually need instead is a proper tool for the task. Does anyone reading this issue know of one such tool that we could use as replacement for this specific use cases?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode/issues/31078#issuecomment-2897189334, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY3UC3L5J3ZRBASVDP35E327Q65DAVCNFSM6AAAAABSHELYRWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQOJXGE4DSMZTGQ. You are receiving this because you are subscribed to this thread.

mbehr1 avatar May 21 '25 17:05 mbehr1

Hmm, since it's been almost 8 years and this issue still isn't resolved, maybe we could assign @Copilot here? I'm sure it'd deal with this flawlessly..

zb3 avatar May 21 '25 19:05 zb3