on master help sign in
tree-sitter-solidity: Use upstream, update queries
20ed8c2Blaž Hrastnik
languages.toml+1−1
@@ -1192,7 +1192,7 @@ language-server = { command = "solc", args = ["--lsp"] }
1192
1192
1193[[grammar]]
1193[[grammar]]
1194name = "solidity"
1194name = "solidity"
1195−source = { git = "https://github.com/slinlee/tree-sitter-solidity", rev = "f3a002274744e859bf64cf3524985f8c31ea84fd" }
1195+source = { git = "https://github.com/JoranHonig/tree-sitter-solidity", rev = "9004b86531cb424bd379424cf7266a4585f2af7d" }
1196
1196
1197[[language]]
1197[[language]]
1198name = "gleam"
1198name = "gleam"
runtime/queries/solidity/highlights.scm+82−52
@@ -1,15 +1,16 @@
1−(comment) @comment
1+; identifiers
2+; -----------
3+(identifier) @variable
4+(yul_identifier) @variable
2
5
3; Pragma
6; Pragma
4(pragma_directive) @tag
7(pragma_directive) @tag
5−(solidity_version_comparison_operator ">=" @tag)
8+(solidity_version_comparison_operator _ @tag)
6−(solidity_version_comparison_operator "<=" @tag)
7−(solidity_version_comparison_operator "=" @tag)
8−(solidity_version_comparison_operator "~" @tag)
9−(solidity_version_comparison_operator "^" @tag)
10
9
11
10
12; Literals
11; Literals
12+; --------
13+
13[
14[
14 (string)
15 (string)
15 (hex_string_literal)
16 (hex_string_literal)
@@ -26,26 +27,38 @@
26 (false)
27 (false)
27] @constant.builtin
28] @constant.builtin
28
29
30+(comment) @comment
31+
32+
33+; Definitions and references
34+; -----------
29
35
30−; Type
31(type_name) @type
36(type_name) @type
32(primitive_type) @type
37(primitive_type) @type
33−(struct_declaration struct_name: (identifier) @type)
38+(user_defined_type (identifier) @type)
34−(enum_declaration enum_type_name: (identifier) @type)
39+
35; Color payable in payable address conversion as type and not as keyword
40; Color payable in payable address conversion as type and not as keyword
36(payable_conversion_expression "payable" @type)
41(payable_conversion_expression "payable" @type)
37−(emit_statement . (identifier) @type)
38−; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {}
39−(override_specifier (identifier) @type)
40; Ensures that delimiters in mapping( ... => .. ) are not colored like types
42; Ensures that delimiters in mapping( ... => .. ) are not colored like types
41(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)
43(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)
42
44
43−
45+; Definitions
44−
46+(struct_declaration
45−; Functions and parameters
47+ name: (identifier) @type)
48+(enum_declaration
49+ name: (identifier) @type)
50+(contract_declaration
51+ name: (identifier) @type)
52+(library_declaration
53+ name: (identifier) @type)
54+(interface_declaration
55+ name: (identifier) @type)
56+(event_definition
57+ name: (identifier) @type)
46
58
47(function_definition
59(function_definition
48− function_name: (identifier) @function)
60+ name: (identifier) @function)
61+
49(modifier_definition
62(modifier_definition
50 name: (identifier) @function)
63 name: (identifier) @function)
51(yul_evm_builtin) @function.builtin
64(yul_evm_builtin) @function.builtin
@@ -55,37 +68,38 @@
55(fallback_receive_definition "receive" @constructor)
68(fallback_receive_definition "receive" @constructor)
56(fallback_receive_definition "fallback" @constructor)
69(fallback_receive_definition "fallback" @constructor)
57
70
58−(modifier_invocation (identifier) @function)
71+(struct_member name: (identifier) @variable.other.member)
72+(enum_value) @constant
59
73
60−; Handles expressions like structVariable.g();
74+; Invocations
61−(call_expression . (member_expression (property_identifier) @function.method))
75+(emit_statement . (identifier) @type)
76+(modifier_invocation (identifier) @function)
62
77
63−; Handles expressions like g();
78+(call_expression . (member_expression property: (identifier) @function.method))
64(call_expression . (identifier) @function)
79(call_expression . (identifier) @function)
65
80
66; Function parameters
81; Function parameters
82+(call_struct_argument name: (identifier) @field)
67−(event_paramater name: (identifier) @variable.parameter) ; TODO fix spelling once fixed upstream
83+(event_paramater name: (identifier) @variable.parameter)
68−(function_definition
69− function_name: (identifier) @variable.parameter)
84+(parameter name: (identifier) @variable.parameter)
70
85
71; Yul functions
86; Yul functions
72(yul_function_call function: (yul_identifier) @function)
87(yul_function_call function: (yul_identifier) @function)
73−
74−; Yul function parameters
75(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter)
88(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter)
76
89
77−(meta_type_expression "type" @keyword)
78
90
91+; Structs and members
79−(member_expression (property_identifier) @variable.other.member)
92+(member_expression property: (identifier) @variable.other.member)
80−(property_identifier) @variable.other.member
81−(struct_expression ((identifier) @variable.other.member . ":"))
93+(struct_expression type: ((identifier) @type .))
82−(enum_value) @variable.other.member
94+(struct_field_assignment name: (identifier) @variable.other.member)
83
95
96+; Tokens
97+; -------
84
98
85; Keywords
99; Keywords
100+(meta_type_expression "type" @keyword)
86[
101[
87 "pragma"
102 "pragma"
88− "import"
89 "contract"
103 "contract"
90 "interface"
104 "interface"
91 "library"
105 "library"
@@ -95,19 +109,6 @@
95 "event"
109 "event"
96 "using"
110 "using"
97 "assembly"
111 "assembly"
98− "switch"
99− "case"
100− "default"
101− "break"
102− "continue"
103− "if"
104− "else"
105− "for"
106− "while"
107− "do"
108− "try"
109− "catch"
110− "return"
111 "emit"
112 "emit"
112 "public"
113 "public"
113 "internal"
114 "internal"
@@ -117,20 +118,47 @@
117 "view"
118 "view"
118 "payable"
119 "payable"
119 "modifier"
120 "modifier"
120− "returns"
121 "memory"
121 "memory"
122 "storage"
122 "storage"
123 "calldata"
123 "calldata"
124− "function"
125 "var"
124 "var"
126− (constant)
125+ "constant"
127 (virtual)
126 (virtual)
128 (override_specifier)
127 (override_specifier)
129 (yul_leave)
128 (yul_leave)
130] @keyword
129] @keyword
131
130
131+[
132+ "for"
133+ "while"
134+ "do"
135+] @keyword.control.repeat
136+
137+[
138+ "break"
139+ "continue"
140+ "if"
141+ "else"
142+ "switch"
143+ "case"
144+ "default"
145+] @keyword.control.conditional
146+
147+[
148+ "try"
149+ "catch"
150+] @keyword.control.exception
151+
152+[
153+ "return"
154+ "returns"
155+] @keyword.control.return
156+
157+"function" @keyword.function
158+
159+"import" @keyword.control.import
132−(import_directive "as" @keyword)
160+(import_directive "as" @keyword.control.import)
133−(import_directive "from" @keyword)
161+(import_directive "from" @keyword.control.import)
134(event_paramater "indexed" @keyword) ; TODO fix spelling once fixed upstream
162(event_paramater "indexed" @keyword) ; TODO fix spelling once fixed upstream
135
163
136; Punctuation
164; Punctuation
@@ -142,7 +170,7 @@
142 "]"
170 "]"
143 "{"
171 "{"
144 "}"
172 "}"
145−] @punctuation.bracket
173+] @punctuation.bracket
146
174
147
175
148[
176[
@@ -185,5 +213,7 @@
185 "--"
213 "--"
186] @operator
214] @operator
187
215
188−(identifier) @variable
216+[
189−(yul_identifier) @variable
217+ "delete"
218+ "new"
219+] @keyword.operator
runtime/queries/solidity/locals.scmnew file+9
@@ -0,0 +1,9 @@
1+(function_definition) @local.scope
2+(block_statement) @local.scope
3+
4+(function_definition (parameter name: (identifier) @local.definition))
5+
6+; still have to support tuple assignments
7+(assignment_expression left: (identifier) @local.definition)
8+
9+(identifier) @local.reference