Skip to content

Commit d6d4625

Browse files
authored
Merge pull request #2101 from lem-project/feat/typescript-tree-sitter
feat(typescript-mode): add tree-sitter syntax highlighting
2 parents 3e1d949 + 376601e commit d6d4625

File tree

4 files changed

+418
-5
lines changed

4 files changed

+418
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(defsystem "lem-typescript-mode"
2-
:depends-on ("lem/core" "lem-lsp-mode" "lem-js-mode")
2+
:depends-on ("lem/core" "lem-lsp-mode" "lem-js-mode" "lem-tree-sitter")
33
:serial t
44
:components ((:file "typescript-mode")
55
(:file "lsp-config")))

extensions/typescript-mode/lsp-config.lisp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
(in-package :lem-typescript-mode/lsp-config)
44

55
(lem-lsp-mode:define-language-spec (typescript-spec lem-typescript-mode:typescript-mode)
6-
:language-id "typescript-tsx"
6+
:language-id "typescript"
7+
:root-uri-patterns '("package.json" "tsconfig.json")
8+
:command '("typescript-language-server" "--stdio")
9+
:install-command "npm install -g typescript-language-server typescript"
10+
:readme-url "https://github.com/typescript-language-server/typescript-language-server"
11+
:connection-mode :stdio)
12+
13+
(lem-lsp-mode:define-language-spec (tsx-spec lem-typescript-mode:tsx-mode)
14+
:language-id "typescriptreact"
715
:root-uri-patterns '("package.json" "tsconfig.json")
816
:command '("typescript-language-server" "--stdio")
917
:install-command "npm install -g typescript-language-server typescript"
Lines changed: 351 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,351 @@
1+
; TypeScript highlights query for Lem editor
2+
; Based on nvim-treesitter and helix conventions
3+
; Works with both typescript and tsx grammars
4+
5+
;; Comments
6+
(comment) @comment
7+
8+
;; Keywords
9+
[
10+
"break"
11+
"case"
12+
"catch"
13+
"class"
14+
"const"
15+
"continue"
16+
"debugger"
17+
"default"
18+
"delete"
19+
"do"
20+
"else"
21+
"export"
22+
"extends"
23+
"finally"
24+
"for"
25+
"function"
26+
"if"
27+
"import"
28+
"in"
29+
"instanceof"
30+
"let"
31+
"new"
32+
"of"
33+
"return"
34+
"static"
35+
"switch"
36+
"throw"
37+
"try"
38+
"typeof"
39+
"var"
40+
"void"
41+
"while"
42+
"with"
43+
"yield"
44+
"await"
45+
"async"
46+
"from"
47+
"as"
48+
"get"
49+
"set"
50+
] @keyword
51+
52+
;; TypeScript-specific keywords
53+
[
54+
"abstract"
55+
"declare"
56+
"enum"
57+
"implements"
58+
"interface"
59+
"keyof"
60+
"namespace"
61+
"override"
62+
"private"
63+
"protected"
64+
"public"
65+
"readonly"
66+
"type"
67+
"satisfies"
68+
"module"
69+
"infer"
70+
"is"
71+
"using"
72+
"asserts"
73+
] @keyword
74+
75+
;; Control flow keywords with specific highlight
76+
[
77+
"return"
78+
"throw"
79+
] @keyword.return
80+
81+
;; Literals - Strings
82+
(string) @string
83+
(template_string) @string
84+
(template_literal_type) @string
85+
(escape_sequence) @string.escape
86+
87+
;; Template string interpolation
88+
(template_substitution
89+
"${" @punctuation.special
90+
"}" @punctuation.special)
91+
92+
;; Literals - Numbers
93+
(number) @number
94+
95+
;; Literals - Boolean and special values
96+
[
97+
(true)
98+
(false)
99+
] @boolean
100+
101+
(null) @constant.builtin
102+
(undefined) @constant.builtin
103+
104+
;; Regular expressions
105+
(regex) @string
106+
(regex_pattern) @string
107+
(regex_flags) @string
108+
109+
;; this, super
110+
(this) @variable.builtin
111+
(super) @variable.builtin
112+
113+
;; Variables
114+
(identifier) @variable
115+
116+
;; Variable declarations
117+
(variable_declarator
118+
name: (identifier) @variable)
119+
120+
;; Object destructuring
121+
(shorthand_property_identifier_pattern) @variable
122+
(object_pattern
123+
(shorthand_property_identifier_pattern) @variable)
124+
125+
;; Array destructuring
126+
(array_pattern
127+
(identifier) @variable)
128+
129+
;; Function definitions
130+
(function_declaration
131+
name: (identifier) @function)
132+
133+
(function_expression
134+
name: (identifier) @function)
135+
136+
(generator_function_declaration
137+
name: (identifier) @function)
138+
139+
;; Arrow functions
140+
(arrow_function
141+
parameter: (identifier) @variable.parameter)
142+
143+
;; Method definitions
144+
(method_definition
145+
name: (property_identifier) @function.method)
146+
147+
;; Function calls
148+
(call_expression
149+
function: (identifier) @function.call)
150+
151+
(call_expression
152+
function: (member_expression
153+
property: (property_identifier) @function.method))
154+
155+
;; New expressions
156+
(new_expression
157+
constructor: (identifier) @type)
158+
159+
;; Class definitions
160+
(class_declaration
161+
name: (type_identifier) @type)
162+
163+
(class_expression
164+
name: (type_identifier) @type)
165+
166+
;; Type annotations
167+
(type_identifier) @type
168+
(predefined_type) @type.builtin
169+
170+
;; Generic type parameters
171+
(type_parameter
172+
name: (type_identifier) @type)
173+
174+
;; Interface and type alias definitions
175+
(interface_declaration
176+
name: (type_identifier) @type)
177+
178+
(type_alias_declaration
179+
name: (type_identifier) @type)
180+
181+
;; Enum definitions
182+
(enum_declaration
183+
name: (identifier) @type)
184+
185+
(enum_body
186+
name: (property_identifier) @constant)
187+
188+
;; Namespace declarations
189+
(ambient_declaration
190+
"declare" @keyword)
191+
192+
;; Property access
193+
(member_expression
194+
property: (property_identifier) @property)
195+
196+
;; Object properties
197+
(property_signature
198+
name: (property_identifier) @property)
199+
200+
(public_field_definition
201+
name: (property_identifier) @property)
202+
203+
(pair
204+
key: (property_identifier) @property)
205+
206+
(shorthand_property_identifier) @property
207+
208+
;; Function parameters
209+
(required_parameter
210+
pattern: (identifier) @variable.parameter)
211+
212+
(optional_parameter
213+
pattern: (identifier) @variable.parameter)
214+
215+
(rest_pattern
216+
(identifier) @variable.parameter)
217+
218+
;; Formal parameters in function signature
219+
(formal_parameters
220+
(identifier) @variable.parameter)
221+
222+
;; Decorators
223+
(decorator
224+
"@" @punctuation.special
225+
(identifier) @attribute)
226+
227+
(decorator
228+
"@" @punctuation.special
229+
(call_expression
230+
function: (identifier) @attribute))
231+
232+
;; Operators
233+
[
234+
"+"
235+
"-"
236+
"*"
237+
"/"
238+
"%"
239+
"**"
240+
"++"
241+
"--"
242+
"="
243+
"+="
244+
"-="
245+
"*="
246+
"/="
247+
"%="
248+
"**="
249+
"=="
250+
"==="
251+
"!="
252+
"!=="
253+
"<"
254+
"<="
255+
">"
256+
">="
257+
"&&"
258+
"||"
259+
"!"
260+
"&"
261+
"|"
262+
"^"
263+
"~"
264+
"<<"
265+
">>"
266+
">>>"
267+
"&="
268+
"|="
269+
"^="
270+
"<<="
271+
">>="
272+
">>>="
273+
"&&="
274+
"||="
275+
"??"
276+
"??="
277+
"?."
278+
"=>"
279+
"..."
280+
] @operator
281+
282+
;; Ternary operator
283+
(ternary_expression
284+
"?" @operator
285+
":" @operator)
286+
287+
;; Type annotation colon
288+
(type_annotation
289+
":" @punctuation.delimiter)
290+
291+
;; Optional chaining and optional properties
292+
(optional_chain) @operator
293+
294+
;; Punctuation - Brackets
295+
[
296+
"("
297+
")"
298+
"["
299+
"]"
300+
"{"
301+
"}"
302+
] @punctuation.bracket
303+
304+
;; Type parameter brackets
305+
[
306+
"<"
307+
">"
308+
] @punctuation.bracket
309+
310+
;; Punctuation - Delimiters
311+
[
312+
";"
313+
"."
314+
","
315+
] @punctuation.delimiter
316+
317+
;; Import/Export statements
318+
(import_statement
319+
"import" @keyword.import)
320+
321+
(export_statement
322+
"export" @keyword.import)
323+
324+
(import_specifier
325+
name: (identifier) @variable)
326+
327+
(export_specifier
328+
name: (identifier) @variable)
329+
330+
;; Named imports/exports
331+
(named_imports
332+
(import_specifier
333+
name: (identifier) @variable))
334+
335+
;; JSX (for TSX files - will be skipped if not present in grammar)
336+
(jsx_element
337+
open_tag: (jsx_opening_element
338+
name: (identifier) @tag))
339+
340+
(jsx_element
341+
close_tag: (jsx_closing_element
342+
name: (identifier) @tag))
343+
344+
(jsx_self_closing_element
345+
name: (identifier) @tag)
346+
347+
(jsx_attribute
348+
(property_identifier) @attribute)
349+
350+
;; Error nodes
351+
(ERROR) @error

0 commit comments

Comments
 (0)