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:
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() {
}
Launch this extension, load any normal text file, and run this command, you see the "Success, activeTextEditor is defined" information message appear.
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.
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.
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.
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...
Great, thanks @jrieken. GitHub isn't showing me a reopen button, can this be reopened?
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.
re https://github.com/Microsoft/vscode/issues/31078#issuecomment-316801062 - forgot to press reopen...
Anyone happen to know where this limit is specified in the source code?
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 :-)"
~ts
window.activeTextEditorLocation(): Location | undefinded
~
Example usage:
~~~ts
'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 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!
Most helpful comment
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!