Skip to content

Commit 30b4e63

Browse files
committed
chore: upgrade lezer lib
This fixes the ino broken syntax parsing
1 parent 20e4fa5 commit 30b4e63

4 files changed

Lines changed: 70 additions & 16 deletions

File tree

bun.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@
157157
"@codemirror/view": "^6.43.9",
158158
"@deadlyjack/ajax": "^1.2.6",
159159
"@emmetio/codemirror6-plugin": "^0.4.1",
160-
"@lezer/common": "^1.5.0",
160+
"@lezer/common": "^1.5.2",
161161
"@lezer/highlight": "^1.2.3",
162-
"@lezer/lr": "^1.4.7",
162+
"@lezer/lr": "^1.4.10",
163163
"@ungap/custom-elements": "^1.3.0",
164164
"@xterm/addon-attach": "^0.12.0",
165165
"@xterm/addon-fit": "^0.11.0",
@@ -210,6 +210,8 @@
210210
"@codemirror/search": "^6.7.1",
211211
"@codemirror/state": "^6.7.1",
212212
"@codemirror/view": "^6.43.9",
213+
"@lezer/common": "^1.5.2",
214+
"@lezer/lr": "^1.4.10",
213215
"tar": "^7.5.22"
214216
},
215217
"browserslist": "cover 100%",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { cppLanguage } from "@codemirror/lang-cpp";
2+
import { classHighlighter, highlightTree } from "@lezer/highlight";
3+
import { describe, expect, it } from "vitest";
4+
5+
function highlightRanges(source) {
6+
const tree = cppLanguage.parser.parse(source);
7+
const inverted = [];
8+
tree.iterate({
9+
enter(node) {
10+
if (node.from > node.to) {
11+
inverted.push({ from: node.from, to: node.to, type: node.name });
12+
}
13+
},
14+
});
15+
16+
const ranges = [];
17+
highlightTree(tree, classHighlighter, (from, to, classes) => {
18+
ranges.push({ from, to, classes });
19+
});
20+
21+
const lastOffset = ranges.at(-1)?.to ?? 0;
22+
return {
23+
inverted,
24+
ranges,
25+
lastLine: source.slice(0, lastOffset).split("\n").length,
26+
};
27+
}
28+
29+
describe("@lezer/lr C highlighting", () => {
30+
it("keeps highlighting after a comment/#define composite skipped node", () => {
31+
const source = [
32+
"",
33+
"// ─────────────────────────────────────────────────────────────",
34+
"// COLORS (RGB565)",
35+
"// ─────────────────────────────────────────────────────────────",
36+
"#define C_BG 0x0841",
37+
"#define C_PANEL 0x1082",
38+
"int setup() {",
39+
" return C_BG;",
40+
"}",
41+
].join("\n");
42+
43+
const { inverted, ranges, lastLine } = highlightRanges(source);
44+
45+
expect(inverted).toEqual([]);
46+
expect(ranges.length).toBeGreaterThan(10);
47+
expect(lastLine).toBe(source.split("\n").length);
48+
expect(ranges.some((range) => range.classes.includes("tok-keyword"))).toBe(
49+
true,
50+
);
51+
});
52+
});

0 commit comments

Comments
 (0)