From 677b3cfa4bd710cc886b33f9730ee496f02b091e Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 3 Apr 2020 14:53:01 +0200 Subject: [PATCH] Disable semantic highlighting in large JS/TS files. Fixes #94321 --- .../src/features/semanticTokens.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/typescript-language-features/src/features/semanticTokens.ts b/extensions/typescript-language-features/src/features/semanticTokens.ts index 78253f1f8c0..373275a6356 100644 --- a/extensions/typescript-language-features/src/features/semanticTokens.ts +++ b/extensions/typescript-language-features/src/features/semanticTokens.ts @@ -24,6 +24,10 @@ export function register(selector: vscode.DocumentSelector, client: ITypeScriptS }); } + +// as we don't do deltas, for performance reasons, don't compute semantic tokens for documents above that limit +const CONTENT_LENGTH_LIMIT = 100000; + /** * Prototype of a DocumentSemanticTokensProvider, relying on the experimental `encodedSemanticClassifications-full` request from the TypeScript server. * As the results retured by the TypeScript server are limited, we also add a Typescript plugin (typescript-vscode-sh-plugin) to enrich the returned token. @@ -40,7 +44,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise { const file = this.client.toOpenedFilePath(document); - if (!file) { + if (!file || document.getText().length > CONTENT_LENGTH_LIMIT) { return null; } return this._provideSemanticTokens(document, { file, start: 0, length: document.getText().length }, token); @@ -48,7 +52,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro async provideDocumentRangeSemanticTokens(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken): Promise { const file = this.client.toOpenedFilePath(document); - if (!file) { + if (!file || document.getText().length > CONTENT_LENGTH_LIMIT) { return null; } const start = document.offsetAt(range.start);