Skip to content

Commit bc57e68

Browse files
committed
Fix text annotations
1 parent 9872fd4 commit bc57e68

12 files changed

+728
-8
lines changed

.changeset/eleven-comics-agree.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@code-hike/lighter": patch
3+
---
4+
5+
Fix text annotations

lib/dist/browser.esm.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,9 @@ const commentsTheme = {
26602660
],
26612661
};
26622662
function extractCommentsFromCode(code, grammar, annotationNames) {
2663-
const lines = highlightTokens(code, grammar, commentsTheme);
2663+
const lines = !grammar
2664+
? highlightText(code)
2665+
: highlightTokens(code, grammar, commentsTheme);
26642666
const allAnnotations = [];
26652667
let lineNumber = 1;
26662668
const cleanLines = lines

lib/dist/index.cjs.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dist/index.esm.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3008,7 +3008,9 @@ const commentsTheme = {
30083008
],
30093009
};
30103010
function extractCommentsFromCode(code, grammar, annotationNames) {
3011-
const lines = highlightTokens(code, grammar, commentsTheme);
3011+
const lines = !grammar
3012+
? highlightText(code)
3013+
: highlightTokens(code, grammar, commentsTheme);
30123014
const allAnnotations = [];
30133015
let lineNumber = 1;
30143016
const cleanLines = lines

lib/src/comments.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IGrammar } from "vscode-textmate";
22
import { Token } from "./annotations";
3-
import { highlightTokens } from "./highlighter";
3+
import { highlightText, highlightTokens } from "./highlighter";
44
import { CodeRange, parseRelativeRanges } from "./range";
55
import { FinalTheme } from "./theme";
66

@@ -35,7 +35,9 @@ export function extractCommentsFromCode(
3535
grammar: IGrammar,
3636
annotationNames: string[]
3737
) {
38-
const lines = highlightTokens(code, grammar, commentsTheme);
38+
const lines = !grammar
39+
? highlightText(code)
40+
: highlightTokens(code, grammar, commentsTheme);
3941

4042
const allAnnotations: Annotation[] = [];
4143

lib/test/__snapshots__/browser.test.ts.snap

+223
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,228 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`extract annottations 1`] = `
4+
{
5+
"annotations": [
6+
{
7+
"name": "foo",
8+
"query": "",
9+
"ranges": [
10+
{
11+
"fromLineNumber": 2,
12+
"toLineNumber": 2,
13+
},
14+
],
15+
},
16+
],
17+
"code": "const x = 1;
18+
const y = 2;",
19+
}
20+
`;
21+
22+
exports[`extract annottations 2`] = `
23+
{
24+
"colors": {
25+
"activeTabBackground": "#1E1E1E",
26+
"activeTabBorder": "#1E1E1E",
27+
"activeTabForeground": "#ffffff",
28+
"activeTabTopBorder": undefined,
29+
"background": "#1E1E1E",
30+
"colorScheme": "dark",
31+
"diffInsertedLineBackground": "#9bb95533",
32+
"diffInsertedTextBackground": "#9ccc2c33",
33+
"diffRemovedLineBackground": "#ff000033",
34+
"diffRemovedTextBackground": "#ff000033",
35+
"editorBackground": "#1E1E1E",
36+
"editorGroupHeaderBackground": "#252526",
37+
"foreground": "#D4D4D4",
38+
"hoverTabBackground": "#2D2D2D",
39+
"hoverTabForeground": "#ffffff80",
40+
"iconForeground": "#C5C5C5",
41+
"inactiveTabBackground": "#2D2D2D",
42+
"inactiveTabForeground": "#ffffff80",
43+
"lineNumberForeground": "#858585",
44+
"listHoverBackground": "#2A2D2E",
45+
"listHoverForeground": undefined,
46+
"listSelectionBackground": "#37373D",
47+
"listSelectionForeground": undefined,
48+
"selectionBackground": "#264F78",
49+
"sideBarBackground": "#252526",
50+
"sideBarBorder": "#252526",
51+
"sideBarForeground": "#D4D4D4",
52+
"tabBorder": "#252526",
53+
"tabsBorder": undefined,
54+
},
55+
"lang": "javascript",
56+
"lines": [
57+
{
58+
"lineNumber": 1,
59+
"tokens": [
60+
{
61+
"content": "const",
62+
"style": {
63+
"color": "#569CD6",
64+
},
65+
},
66+
{
67+
"content": " ",
68+
"style": {
69+
"color": "#D4D4D4",
70+
},
71+
},
72+
{
73+
"content": "x",
74+
"style": {
75+
"color": "#4FC1FF",
76+
},
77+
},
78+
{
79+
"content": " = ",
80+
"style": {
81+
"color": "#D4D4D4",
82+
},
83+
},
84+
{
85+
"content": "1",
86+
"style": {
87+
"color": "#B5CEA8",
88+
},
89+
},
90+
{
91+
"content": ";",
92+
"style": {
93+
"color": "#D4D4D4",
94+
},
95+
},
96+
],
97+
},
98+
{
99+
"annotationName": "foo",
100+
"annotationQuery": "",
101+
"fromLineNumber": 2,
102+
"lines": [
103+
{
104+
"lineNumber": 2,
105+
"tokens": [
106+
{
107+
"content": "const",
108+
"style": {
109+
"color": "#569CD6",
110+
},
111+
},
112+
{
113+
"content": " ",
114+
"style": {
115+
"color": "#D4D4D4",
116+
},
117+
},
118+
{
119+
"content": "y",
120+
"style": {
121+
"color": "#4FC1FF",
122+
},
123+
},
124+
{
125+
"content": " = ",
126+
"style": {
127+
"color": "#D4D4D4",
128+
},
129+
},
130+
{
131+
"content": "2",
132+
"style": {
133+
"color": "#B5CEA8",
134+
},
135+
},
136+
{
137+
"content": ";",
138+
"style": {
139+
"color": "#D4D4D4",
140+
},
141+
},
142+
],
143+
},
144+
],
145+
"toLineNumber": 2,
146+
},
147+
],
148+
}
149+
`;
150+
151+
exports[`extract annottations from text 1`] = `
152+
{
153+
"annotations": [],
154+
"code": "const x = 1;
155+
// foo[3:5]
156+
const y = 2;",
157+
}
158+
`;
159+
160+
exports[`extract annottations from text 2`] = `
161+
{
162+
"colors": {
163+
"activeTabBackground": "#1E1E1E",
164+
"activeTabBorder": "#1E1E1E",
165+
"activeTabForeground": "#ffffff",
166+
"activeTabTopBorder": undefined,
167+
"background": "#1E1E1E",
168+
"colorScheme": "dark",
169+
"diffInsertedLineBackground": "#9bb95533",
170+
"diffInsertedTextBackground": "#9ccc2c33",
171+
"diffRemovedLineBackground": "#ff000033",
172+
"diffRemovedTextBackground": "#ff000033",
173+
"editorBackground": "#1E1E1E",
174+
"editorGroupHeaderBackground": "#252526",
175+
"foreground": "#D4D4D4",
176+
"hoverTabBackground": "#2D2D2D",
177+
"hoverTabForeground": "#ffffff80",
178+
"iconForeground": "#C5C5C5",
179+
"inactiveTabBackground": "#2D2D2D",
180+
"inactiveTabForeground": "#ffffff80",
181+
"lineNumberForeground": "#858585",
182+
"listHoverBackground": "#2A2D2E",
183+
"listHoverForeground": undefined,
184+
"listSelectionBackground": "#37373D",
185+
"listSelectionForeground": undefined,
186+
"selectionBackground": "#264F78",
187+
"sideBarBackground": "#252526",
188+
"sideBarBorder": "#252526",
189+
"sideBarForeground": "#D4D4D4",
190+
"tabBorder": "#252526",
191+
"tabsBorder": undefined,
192+
},
193+
"lang": "text",
194+
"lines": [
195+
{
196+
"lineNumber": 1,
197+
"tokens": [
198+
{
199+
"content": "const x = 1;",
200+
"style": {},
201+
},
202+
],
203+
},
204+
{
205+
"lineNumber": 2,
206+
"tokens": [
207+
{
208+
"content": "// foo[3:5]",
209+
"style": {},
210+
},
211+
],
212+
},
213+
{
214+
"lineNumber": 3,
215+
"tokens": [
216+
{
217+
"content": "const y = 2;",
218+
"style": {},
219+
},
220+
],
221+
},
222+
],
223+
}
224+
`;
225+
3226
exports[`highlight js 1`] = `
4227
{
5228
"colors": {

0 commit comments

Comments
 (0)