Skip to content

Commit 20ed8c2

Browse files
committed
tree-sitter-solidity: Use upstream, update queries
1 parent 44b4479 commit 20ed8c2

File tree

3 files changed

+92
-53
lines changed

3 files changed

+92
-53
lines changed

languages.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ language-server = { command = "solc", args = ["--lsp"] }
11921192

11931193
[[grammar]]
11941194
name = "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" }
11961196

11971197
[[language]]
11981198
name = "gleam"

runtime/queries/solidity/highlights.scm

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
(comment) @comment
1+
; identifiers
2+
; -----------
3+
(identifier) @variable
4+
(yul_identifier) @variable
25

36
; Pragma
47
(pragma_directive) @tag
5-
(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)
8+
(solidity_version_comparison_operator _ @tag)
109

1110

1211
; Literals
12+
; --------
13+
1314
[
1415
(string)
1516
(hex_string_literal)
@@ -26,26 +27,38 @@
2627
(false)
2728
] @constant.builtin
2829

30+
(comment) @comment
31+
32+
33+
; Definitions and references
34+
; -----------
2935

30-
; Type
3136
(type_name) @type
3237
(primitive_type) @type
33-
(struct_declaration struct_name: (identifier) @type)
34-
(enum_declaration enum_type_name: (identifier) @type)
38+
(user_defined_type (identifier) @type)
39+
3540
; Color payable in payable address conversion as type and not as keyword
3641
(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)
4042
; Ensures that delimiters in mapping( ... => .. ) are not colored like types
4143
(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)
4244

43-
44-
45-
; Functions and parameters
45+
; Definitions
46+
(struct_declaration
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)
4658

4759
(function_definition
48-
function_name: (identifier) @function)
60+
name: (identifier) @function)
61+
4962
(modifier_definition
5063
name: (identifier) @function)
5164
(yul_evm_builtin) @function.builtin
@@ -55,37 +68,38 @@
5568
(fallback_receive_definition "receive" @constructor)
5669
(fallback_receive_definition "fallback" @constructor)
5770

58-
(modifier_invocation (identifier) @function)
71+
(struct_member name: (identifier) @variable.other.member)
72+
(enum_value) @constant
5973

60-
; Handles expressions like structVariable.g();
61-
(call_expression . (member_expression (property_identifier) @function.method))
74+
; Invocations
75+
(emit_statement . (identifier) @type)
76+
(modifier_invocation (identifier) @function)
6277

63-
; Handles expressions like g();
78+
(call_expression . (member_expression property: (identifier) @function.method))
6479
(call_expression . (identifier) @function)
6580

6681
; Function parameters
67-
(event_paramater name: (identifier) @variable.parameter) ; TODO fix spelling once fixed upstream
68-
(function_definition
69-
function_name: (identifier) @variable.parameter)
82+
(call_struct_argument name: (identifier) @field)
83+
(event_paramater name: (identifier) @variable.parameter)
84+
(parameter name: (identifier) @variable.parameter)
7085

7186
; Yul functions
7287
(yul_function_call function: (yul_identifier) @function)
73-
74-
; Yul function parameters
7588
(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter)
7689

77-
(meta_type_expression "type" @keyword)
7890

79-
(member_expression (property_identifier) @variable.other.member)
80-
(property_identifier) @variable.other.member
81-
(struct_expression ((identifier) @variable.other.member . ":"))
82-
(enum_value) @variable.other.member
91+
; Structs and members
92+
(member_expression property: (identifier) @variable.other.member)
93+
(struct_expression type: ((identifier) @type .))
94+
(struct_field_assignment name: (identifier) @variable.other.member)
8395

96+
; Tokens
97+
; -------
8498

8599
; Keywords
100+
(meta_type_expression "type" @keyword)
86101
[
87102
"pragma"
88-
"import"
89103
"contract"
90104
"interface"
91105
"library"
@@ -95,19 +109,6 @@
95109
"event"
96110
"using"
97111
"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"
111112
"emit"
112113
"public"
113114
"internal"
@@ -117,20 +118,47 @@
117118
"view"
118119
"payable"
119120
"modifier"
120-
"returns"
121121
"memory"
122122
"storage"
123123
"calldata"
124-
"function"
125124
"var"
126-
(constant)
125+
"constant"
127126
(virtual)
128127
(override_specifier)
129128
(yul_leave)
130129
] @keyword
131130

132-
(import_directive "as" @keyword)
133-
(import_directive "from" @keyword)
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
160+
(import_directive "as" @keyword.control.import)
161+
(import_directive "from" @keyword.control.import)
134162
(event_paramater "indexed" @keyword) ; TODO fix spelling once fixed upstream
135163

136164
; Punctuation
@@ -142,7 +170,7 @@
142170
"]"
143171
"{"
144172
"}"
145-
] @punctuation.bracket
173+
] @punctuation.bracket
146174

147175

148176
[
@@ -185,5 +213,7 @@
185213
"--"
186214
] @operator
187215

188-
(identifier) @variable
189-
(yul_identifier) @variable
216+
[
217+
"delete"
218+
"new"
219+
] @keyword.operator

runtime/queries/solidity/locals.scm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)