Skip to content

Commit 1603c5f

Browse files
committed
add emmyluadoc tree-sitter for highlight
1 parent e71a26d commit 1603c5f

File tree

7 files changed

+304
-14
lines changed

7 files changed

+304
-14
lines changed

extension.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ repository = "https://github.com/EmmyLuaLs/Zed-EmmyLua"
88

99
[language_servers.emmylua]
1010
name = "EmmyLua Language Server"
11-
languages = ["EmmyLua", "Lua"]
11+
languages = ["EmmyLua", "Lua", "EmmyLuadoc"]
1212

1313
[grammars.lua]
1414
repository = "https://github.com/tree-sitter-grammars/tree-sitter-lua"
1515
commit = "d76023017f7485eae629cb60d406c7a1ca0f40c9"
16+
[grammars.emmyluadoc]
17+
repository = "https://github.com/EmmyLuaLs/tree-sitter-emmyluadoc"
18+
commit = "c35436fb77c61dff0a41e3e774d8dc0373752f37"

languages/emmylua/highlights.scm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,6 @@
192192
;; Regular comments
193193
(comment) @comment
194194

195-
;; EmmyLua Doc Comments - Use @attribute for visibility
196-
; EmmyLua annotations like @param, @class, @return, etc.
197-
((comment
198-
content: (comment_content) @attribute)
199-
(#match? @attribute "^-@(class|alias|type|enum|interface|field|param|return|generic|overload|async|nodiscard|deprecated|diagnostic|cast|meta|module|operator|see|source|version|as|public|private|protected|package)"))
200-
201-
; EmmyLua enum values: ---| 'value' or --- | "value"
202-
; These are typically used after @alias to define enum options
203-
; Supports optional spaces between --- and |
204-
((comment
205-
content: (comment_content) @string.special)
206-
(#match? @string.special "^-\\s*\\|\\s*['\"]"))
207-
208195
(hash_bang_line) @preproc
209196

210197
(number) @number

languages/emmylua/injections.scm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
;; Injections for Lua code
22

3+
;; EmmyLua Doc comments injection
4+
;; Inject --- comments as emmyluadoc language
5+
;; The emmyluadoc grammar now supports --- prefix, so we can directly inject
6+
((comment
7+
(comment_content) @injection.content)
8+
(#match? @injection.content "^-")
9+
(#set! injection.language "emmyluadoc"))
10+
311
;; LuaJIT FFI C code injection
412
((function_call
513
name: [

languages/emmyluadoc/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name = "EmmyLuadoc"
2+
grammar = "emmyluadoc"
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
; Highlights query for EmmyLuaDoc
2+
; 用于语法高亮的查询文件
3+
4+
; ============================================
5+
; Lua 注释前缀 (Comment Prefix)
6+
; ============================================
7+
8+
(comment_prefix) @comment
9+
10+
; ============================================
11+
; 注解关键字 (Annotation Keywords)
12+
; ============================================
13+
14+
; 使用匿名节点匹配注解标记
15+
"@class" @keyword
16+
"@field" @keyword
17+
"@type" @keyword
18+
"@param" @keyword
19+
"@return" @keyword
20+
"@generic" @keyword
21+
"@vararg" @keyword
22+
"@overload" @keyword
23+
"@see" @keyword
24+
"@alias" @keyword
25+
"@enum" @keyword
26+
"@module" @keyword
27+
"@cast" @keyword
28+
"@version" @keyword
29+
"@diagnostic" @keyword
30+
"@operator" @keyword
31+
32+
; 特殊注解节点(这些没有 @ 前缀的文本节点)
33+
(deprecated_annotation) @keyword
34+
(private_annotation) @keyword
35+
(protected_annotation) @keyword
36+
(public_annotation) @keyword
37+
(package_annotation) @keyword
38+
(async_annotation) @keyword
39+
(nodiscard_annotation) @keyword
40+
(meta_annotation) @keyword
41+
42+
; ============================================
43+
; 类型关键字 (Type Keywords)
44+
; ============================================
45+
46+
[
47+
"fun"
48+
"table"
49+
] @keyword.type
50+
51+
; ============================================
52+
; 基础类型 (Basic Types)
53+
; ============================================
54+
55+
((identifier) @type.builtin
56+
(#match? @type.builtin "^(string|number|boolean|table|function|thread|userdata|nil|any|unknown|self)$"))
57+
58+
; 自定义类型
59+
(basic_type
60+
(identifier) @type)
61+
62+
; ============================================
63+
; 类定义 (Class Definitions)
64+
; ============================================
65+
66+
(class_annotation
67+
name: (identifier) @type.definition)
68+
69+
(class_annotation
70+
parent: (type_list
71+
(type
72+
(primary_type
73+
(basic_type
74+
(identifier) @type)))))
75+
76+
; ============================================
77+
; 字段和参数 (Fields and Parameters)
78+
; ============================================
79+
80+
(field_annotation
81+
name: (identifier) @variable.member)
82+
83+
(param_annotation
84+
name: (identifier) @variable.parameter)
85+
86+
(return_annotation
87+
name: (identifier)? @variable.parameter)
88+
89+
(param_def
90+
name: (identifier) @variable.parameter)
91+
92+
; ============================================
93+
; 泛型 (Generics)
94+
; ============================================
95+
96+
(generic_annotation
97+
name: (identifier) @type.parameter)
98+
99+
(generic_type
100+
base: (identifier) @type)
101+
102+
; ============================================
103+
; 别名和枚举 (Aliases and Enums)
104+
; ============================================
105+
106+
(alias_annotation
107+
name: (identifier) @type.definition)
108+
109+
(enum_annotation
110+
name: (identifier) @type.definition)
111+
112+
; ============================================
113+
; 可见性修饰符 (Visibility Modifiers)
114+
; ============================================
115+
116+
[
117+
"public"
118+
"private"
119+
"protected"
120+
"package"
121+
] @keyword.modifier
122+
123+
; ============================================
124+
; 操作符 (Operators)
125+
; ============================================
126+
127+
[
128+
"call"
129+
"add" "sub" "mul" "div" "mod" "pow"
130+
"concat"
131+
"len"
132+
"eq" "lt" "le"
133+
"unm"
134+
"bnot" "band" "bor" "bxor" "shl" "shr"
135+
] @operator
136+
137+
; ============================================
138+
; 字面量 (Literals)
139+
; ============================================
140+
141+
(string) @string
142+
143+
(number) @number
144+
145+
(boolean) @boolean
146+
147+
; ============================================
148+
; 标点符号 (Punctuation)
149+
; ============================================
150+
151+
[
152+
":"
153+
"|"
154+
","
155+
"?"
156+
] @punctuation.delimiter
157+
158+
; 类型续行中的 |
159+
(type_continuation
160+
"|" @punctuation.delimiter)
161+
162+
[
163+
"("
164+
")"
165+
"["
166+
"]"
167+
"<"
168+
">"
169+
] @punctuation.bracket
170+
171+
; ============================================
172+
; 引用和诊断 (References and Diagnostics)
173+
; ============================================
174+
175+
(see_annotation
176+
reference: (identifier) @variable)
177+
178+
(diagnostic_annotation
179+
action: [
180+
"disable"
181+
"enable"
182+
"disable-next-line"
183+
"disable-line"
184+
] @keyword.directive)
185+
186+
(diagnostic_list
187+
(identifier) @constant)
188+
189+
; ============================================
190+
; 模块名 (Module Names)
191+
; ============================================
192+
193+
(module_annotation
194+
name: (string) @module)
195+
196+
; ============================================
197+
; 版本 (Version)
198+
; ============================================
199+
200+
(version_annotation
201+
version: [
202+
(identifier) @constant
203+
(string) @string
204+
])
205+
206+
; ============================================
207+
; 数组类型标记 (Array Type Markers)
208+
; ============================================
209+
210+
(array_type
211+
"[" @punctuation.bracket
212+
"]" @punctuation.bracket)
213+
214+
; ============================================
215+
; 函数类型 (Function Types)
216+
; ============================================
217+
218+
(function_type
219+
"fun" @keyword.function
220+
":" @punctuation.delimiter)
221+
222+
; ============================================
223+
; 表类型 (Table Types)
224+
; ============================================
225+
226+
(table_type
227+
"table" @type.builtin)

languages/emmyluadoc/locals.scm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; Locals query for EmmyLuaDoc
2+
; 用于作用域分析的查询文件
3+
4+
; 定义作用域
5+
(class_annotation) @scope
6+
7+
; 类定义
8+
(class_annotation
9+
name: (identifier) @definition.type)
10+
11+
; 字段定义
12+
(field_annotation
13+
name: (identifier) @definition.field)
14+
15+
; 参数定义
16+
(param_annotation
17+
name: (identifier) @definition.parameter)
18+
19+
; 泛型定义
20+
(generic_annotation
21+
name: (identifier) @definition.type)
22+
23+
; 别名定义
24+
(alias_annotation
25+
name: (identifier) @definition.type)
26+
27+
; 枚举定义
28+
(enum_annotation
29+
name: (identifier) @definition.type)
30+
31+
; 类型引用
32+
(basic_type
33+
(identifier) @reference)
34+
35+
; 参数引用
36+
(param_def
37+
name: (identifier) @reference)

languages/emmyluadoc/tags.scm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; Tags query for EmmyLuaDoc
2+
; 用于生成符号标签(用于代码导航)
3+
4+
; 类定义
5+
(class_annotation
6+
name: (identifier) @name) @definition.class
7+
8+
; 字段定义
9+
(field_annotation
10+
name: (identifier) @name) @definition.field
11+
12+
; 枚举定义
13+
(enum_annotation
14+
name: (identifier) @name) @definition.enum
15+
16+
; 别名定义
17+
(alias_annotation
18+
name: (identifier) @name) @definition.type
19+
20+
; 函数参数
21+
(param_annotation
22+
name: (identifier) @name) @definition.parameter
23+
24+
; 泛型参数
25+
(generic_annotation
26+
name: (identifier) @name) @definition.type

0 commit comments

Comments
 (0)