Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(solidity): add textobject queries for solidity #10318

Merged
merged 12 commits into from
Apr 9, 2024
Merged
2 changes: 1 addition & 1 deletion book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
| smali | ✓ | | ✓ | |
| smithy | ✓ | | | `cs` |
| sml | ✓ | | | |
| solidity | ✓ | | | `solc` |
| solidity | ✓ | | | `solc` |
| spicedb | ✓ | | | |
| sql | ✓ | | | |
| sshclientconfig | ✓ | | | |
Expand Down
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ language-servers = [ "solc" ]

[[grammar]]
name = "solidity"
source = { git = "https://github.com/JoranHonig/tree-sitter-solidity", rev = "9004b86531cb424bd379424cf7266a4585f2af7d" }
source = { git = "https://github.com/JoranHonig/tree-sitter-solidity", rev = "08338dcee32603383fcef08f36321900bb7a354b" }

[[language]]
name = "gleam"
Expand Down
18 changes: 11 additions & 7 deletions runtime/queries/solidity/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
; identifiers
; -----------
(identifier) @variable
(yul_identifier) @variable

; Pragma
(pragma_directive) @tag
(solidity_version_comparison_operator _ @tag)
Expand Down Expand Up @@ -36,6 +31,7 @@
(type_name) @type
(primitive_type) @type
(user_defined_type (identifier) @type)
(type_alias (identifier) @type)

; Color payable in payable address conversion as type and not as keyword
(payable_conversion_expression "payable" @type)
Expand Down Expand Up @@ -80,7 +76,7 @@

; Function parameters
(call_struct_argument name: (identifier) @field)
(event_paramater name: (identifier) @variable.parameter)
(event_parameter name: (identifier) @variable.parameter)
(parameter name: (identifier) @variable.parameter)

; Yul functions
Expand All @@ -99,6 +95,7 @@
; Keywords
(meta_type_expression "type" @keyword)
[
"abstract"
"pragma"
"contract"
"interface"
Expand Down Expand Up @@ -159,7 +156,7 @@
"import" @keyword.control.import
(import_directive "as" @keyword.control.import)
(import_directive "from" @keyword.control.import)
(event_paramater "indexed" @keyword) ; TODO fix spelling once fixed upstream
(event_parameter "indexed" @keyword)

; Punctuation

Expand Down Expand Up @@ -217,3 +214,10 @@
"delete"
"new"
] @keyword.operator

; identifiers
; -----------
((identifier) @variable.builtin
(#match? @variable.builtin "^(this|msg|block|tx)$"))
(identifier) @variable
(yul_identifier) @variable
54 changes: 54 additions & 0 deletions runtime/queries/solidity/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(function_definition
body: (_) @function.inside) @function.around

(constructor_definition
body: (_) @function.inside) @function.around

(fallback_receive_definition
body: (_) @function.inside) @function.around

(yul_function_definition
(yul_block) @function.inside) @function.around

(function_definition
((parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(constructor_definition
((parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(return_type_definition
((parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(modifier_definition
((parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(event_definition
((event_parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(error_declaration
((error_parameter) @parameter.inside . ","? @parameter.around) @parameter.around)

(call_argument
((call_struct_argument) @parameter.inside . ","? @parameter.around) @parameter.around)

(call_expression
((call_argument) @parameter.inside . ","? @parameter.around) @parameter.around)

(variable_declaration_tuple
((variable_declaration) @parameter.inside . ","? @parameter.around) @parameter.around)

(emit_statement
((call_argument) @parameter.inside . ","? @parameter.around) @parameter.around)

(revert_arguments
((call_argument) @parameter.inside . ","? @parameter.around) @parameter.around)

(struct_declaration
body: (_) @class.inside) @class.around

(enum_declaration
body: (_) @class.inside) @class.around

(comment) @comment.inside

(comment)+ @comment.around
Loading