Skip to content

Commit 8f7289b

Browse files
Disable latex parser on vscode version >= 1.98.0 (#109)
* Disable latex parser on vscode version >= 1.98.0 * Update package.json Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com> --------- Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com>
1 parent 7774fc3 commit 8f7289b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "parse-tree",
33
"displayName": "Parse tree",
44
"description": "Access document syntax using tree-sitter",
5-
"version": "0.37.1",
5+
"version": "0.37.2",
66
"publisher": "pokey",
77
"repository": {
88
"type": "git",
@@ -99,6 +99,7 @@
9999
"typescript": "^4.5.5"
100100
},
101101
"dependencies": {
102+
"semver": "7.7.2",
102103
"web-tree-sitter": "^0.25.3"
103104
}
104105
}

src/extension.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import * as treeSitter from "web-tree-sitter";
33
import * as path from "path";
44
import * as fs from "fs";
5+
import * as semver from "semver";
56
import { LanguageStillLoadingError, UnsupportedLanguageError } from "./errors";
67

78
interface Language {
@@ -68,6 +69,20 @@ export async function activate(context: vscode.ExtensionContext) {
6869
// Parse of all visible documents
6970
const trees: { [uri: string]: treeSitter.Tree } = {};
7071

72+
/**
73+
* FIXME: On newer vscode versions the latex Tree sitter parser throws memory errors
74+
* https://github.com/cursorless-dev/cursorless/issues/2879
75+
*/
76+
const disableLatex = semver.gte(vscode.version, "1.98.0");
77+
78+
const validateGetLatex = (languageId: string) => {
79+
if (languageId === "latex" && disableLatex) {
80+
throw new Error(
81+
"Latex is disabled on vscode versions >= 1.98.0. See https://github.com/cursorless-dev/cursorless/issues/2879"
82+
);
83+
}
84+
};
85+
7186
/**
7287
* Load the parser model for a given language
7388
* @param languageId The vscode language id of the language to load
@@ -82,6 +97,10 @@ export async function activate(context: vscode.ExtensionContext) {
8297
return true;
8398
}
8499

100+
if (languageId === "latex" && disableLatex) {
101+
return false;
102+
}
103+
85104
let absolute;
86105
if (path.isAbsolute(language.module)) {
87106
absolute = language.module;
@@ -244,6 +263,7 @@ export async function activate(context: vscode.ExtensionContext) {
244263
const languageId = document.languageId;
245264

246265
if (languageId in languages) {
266+
validateGetLatex(document.languageId);
247267
throw new LanguageStillLoadingError(languageId);
248268
} else {
249269
throw new UnsupportedLanguageError(languageId);
@@ -263,6 +283,7 @@ export async function activate(context: vscode.ExtensionContext) {
263283
console.warn(
264284
"vscode-parse-tree: getLanguage is deprecated, use createQuery(languageId, source) instead."
265285
);
286+
validateGetLatex(languageId);
266287
return languages[languageId]?.parser?.language ?? undefined;
267288
},
268289

@@ -272,6 +293,7 @@ export async function activate(context: vscode.ExtensionContext) {
272293
): treeSitter.Query | undefined {
273294
const language = languages[languageId]?.parser?.language;
274295
if (language == null) {
296+
validateGetLatex(languageId);
275297
return undefined;
276298
}
277299
return new treeSitter.Query(language, source);

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
88
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==
99

10-
"@cursorless/tree-sitter-wasms@0.2.5":
11-
version "0.2.5"
12-
resolved "https://registry.yarnpkg.com/@cursorless/tree-sitter-wasms/-/tree-sitter-wasms-0.2.5.tgz#575c4961ff56627f3e544cfc9a9983360901ab83"
13-
integrity sha512-nyxFQb2Qj7uQSPxZ+/7dPQV4Q7pzzgwPioS1mYoMSCLQEsU9GokvM+5jrQL60aXXaODqgJEmGvuIo9CQIZ6qPw==
10+
"@cursorless/tree-sitter-wasms@0.3.0":
11+
version "0.3.0"
12+
resolved "https://registry.yarnpkg.com/@cursorless/tree-sitter-wasms/-/tree-sitter-wasms-0.3.0.tgz#2b337faadca78e9251e76eeb46d18828d5a2e44e"
13+
integrity sha512-CfR0xdzNzP5aG+N+/0DmX5CBjPjWLRdY8WXp54SyfAp8B4UNOVrKjLfWnKXDzo83gv+zJeNdQDSxUE3FY0eUYQ==
1414

1515
"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0":
1616
version "4.4.0"
@@ -953,6 +953,11 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
953953
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
954954
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
955955

956+
semver@7.7.2:
957+
version "7.7.2"
958+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.2.tgz#67d99fdcd35cec21e6f8b87a7fd515a33f982b58"
959+
integrity sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==
960+
956961
semver@^7.5.4:
957962
version "7.5.4"
958963
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"

0 commit comments

Comments
 (0)