on master help sign in
Improve llvm highlighting and queries (#1388)

* Improve llvm highlighting and queries The llvm tree-sitter parser was updated to support scopes and more accurate highlighting. * Group highlight expressions better

commit8c29b76bccc51c19c90f7c9ee156fe2cb6f52e2c authorSebastian Neubauer <Flakebi@users.noreply.github.com> dateWed 29 Dec 2021, 10:30 (5 years ago) parentf1ed042
6 files changed+193−11
book/src/generated/lang-support.md+1−1 helix-syntax/languages/tree-sitter-llvm+1−1 runtime/queries/llvm/highlights.scm+153−9 runtime/queries/llvm/indents.toml+8 runtime/queries/llvm/locals.scm+14 runtime/queries/llvm/textobjects.scm+16
book/src/generated/lang-support.md+1−1
@@ -21,7 +21,7 @@
2121| julia | ✓ | | | `julia` |
2222| latex | ✓ | | | |
2323| ledger | ✓ | | | |
24−| llvm | ✓ | | | |
24+| llvm | ✓ | ✓ | ✓ | |
2525| lua | ✓ | | ✓ | |
2626| markdown | ✓ | | | |
2727| mint | | | | `mint` |
helix-syntax/languages/tree-sitter-llvm+1−1

Submodule changed.

runtime/queries/llvm/highlights.scm+153−9
@@ -1,14 +1,158 @@
11(type) @type
2−(statement) @keyword.operator
2+(type_keyword) @type.builtin
3+
4+(type [
5+ (local_var)
6+ (global_var)
7+ ] @type)
8+
9+(argument) @variable.parameter
10+
11+(_ inst_name: _ @keyword.operator)
12+
13+[
14+ "catch"
15+ "filter"
16+] @keyword.operator
17+
18+[
19+ "to"
20+ "nuw"
21+ "nsw"
22+ "exact"
23+ "unwind"
24+ "from"
25+ "cleanup"
26+ "swifterror"
27+ "volatile"
28+ "inbounds"
29+ "inrange"
30+ (icmp_cond)
31+ (fcmp_cond)
32+ (fast_math)
33+] @keyword.control
34+
35+(_ callee: _ @function)
36+(function_header name: _ @function)
37+
38+[
39+ "declare"
40+ "define"
41+ (calling_conv)
42+] @keyword.function
43+
44+[
45+ "target"
46+ "triple"
47+ "datalayout"
48+ "source_filename"
49+ "addrspace"
50+ "blockaddress"
51+ "align"
52+ "syncscope"
53+ "within"
54+ "uselistorder"
55+ "uselistorder_bb"
56+ "module"
57+ "asm"
58+ "sideeffect"
59+ "alignstack"
60+ "inteldialect"
61+ "unwind"
62+ "type"
63+ "global"
64+ "constant"
65+ "externally_initialized"
66+ "alias"
67+ "ifunc"
68+ "section"
69+ "comdat"
70+ "thread_local"
71+ "localdynamic"
72+ "initialexec"
73+ "localexec"
74+ "any"
75+ "exactmatch"
76+ "largest"
77+ "nodeduplicate"
78+ "samesize"
79+ "distinct"
80+ "attributes"
81+ "vscale"
82+ "no_cfi"
83+ (linkage_aux)
84+ (dso_local)
85+ (visibility)
86+ (dll_storage_class)
87+ (unnamed_addr)
88+ (attribute_name)
89+] @keyword
90+
91+
92+(function_header [
93+ (linkage)
94+ (calling_conv)
95+ (unnamed_addr)
96+ ] @keyword.function)
97+
98+[
99+ (string)
100+ (cstring)
101+] @string
102+
3103(number) @constant.numeric.integer
4104(comment) @comment
5−(string) @string
6105(label) @label
7−(keyword) @keyword
8−"ret" @keyword.control.return
9−(boolean) @constant.builtin.boolean
106+(_ inst_name: "ret" @keyword.control.return)
10107(float) @constant.numeric.float
11−(constant) @constant
12−(identifier) @variable
13−(symbol) @punctuation.delimiter
14−(bracket) @punctuation.bracket
108+
109+[
110+ (local_var)
111+ (global_var)
112+] @variable
113+
114+[
115+ (struct_value)
116+ (array_value)
117+ (vector_value)
118+] @constructor
119+
120+[
121+ "("
122+ ")"
123+ "["
124+ "]"
125+ "{"
126+ "}"
127+ "<"
128+ ">"
129+ "<{"
130+ "}>"
131+] @punctuation.bracket
132+
133+[
134+ ","
135+ ":"
136+] @punctuation.delimiter
137+
138+[
139+ "="
140+ "|"
141+ "x"
142+ "..."
143+] @operator
144+
145+[
146+ "true"
147+ "false"
148+] @constant.builtin.boolean
149+
150+[
151+ "undef"
152+ "poison"
153+ "null"
154+ "none"
155+ "zeroinitializer"
156+] @constant.builtin
157+
158+(ERROR) @error
runtime/queries/llvm/indents.tomlnew file+8
@@ -0,0 +1,8 @@
1+indent = [
2+ "function_body",
3+ "instruction",
4+]
5+
6+outdent = [
7+ "}",
8+]
runtime/queries/llvm/locals.scmnew file+14
@@ -0,0 +1,14 @@
1+; Scopes
2+
3+(function_body) @local.scope
4+
5+; Definitions
6+
7+(argument
8+ (value (var (local_var) @local.definition)))
9+
10+(instruction
11+ (local_var) @local.definition)
12+
13+; References
14+(local_var) @local.reference
runtime/queries/llvm/textobjects.scmnew file+16
@@ -0,0 +1,16 @@
1+(define
2+ body: (_) @function.inside) @function.around
3+
4+(struct_type
5+ (struct_body) @class.inside) @class.around
6+
7+(packed_struct_type
8+ (struct_body) @class.inside) @class.around
9+
10+(array_type
11+ (array_vector_body) @class.inside) @class.around
12+
13+(vector_type
14+ (array_vector_body) @class.inside) @class.around
15+
16+(argument) @parameter.inside