From 85f698d5d73d5b28c6fb5fef6f14c4bfe9eb3a64 Mon Sep 17 00:00:00 2001 From: Valentin B <703631+beeb@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:42:51 +0200 Subject: [PATCH] feat(solidity): add textobject queries for solidity (#10318) * feat: add textobject queries for solidity * feat(solidity): add parameter textobject query for call expressions * feat(solidity): add more textobject queries for parameters * feat(solidity): add yul function textobject query * feat(solidity): add textobject query for emit statement arguments * feat(solidity): add textobject query for revert call arguments * feat(solidity): update tree-sitter grammar and fix typo * docs: update auto-generated docs * fix(solidity): fix identifiers highlight query priority * feat(solidity): add "abstract" to keywords list * feat(solidity): add highlight query for type alias * feat(solidity): add variable builtin highlight queries --- book/src/generated/lang-support.md | 2 +- languages.toml | 2 +- runtime/queries/solidity/highlights.scm | 18 +++++--- runtime/queries/solidity/textobjects.scm | 54 ++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 runtime/queries/solidity/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 4cd67bc5cf8b..fb1c7bd5a473 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -173,7 +173,7 @@ | smali | ✓ | | ✓ | | | smithy | ✓ | | | `cs` | | sml | ✓ | | | | -| solidity | ✓ | | | `solc` | +| solidity | ✓ | ✓ | | `solc` | | spicedb | ✓ | | | | | sql | ✓ | | | | | sshclientconfig | ✓ | | | | diff --git a/languages.toml b/languages.toml index b700c326524e..0f70a73305a1 100644 --- a/languages.toml +++ b/languages.toml @@ -1787,7 +1787,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" diff --git a/runtime/queries/solidity/highlights.scm b/runtime/queries/solidity/highlights.scm index 08178c362a03..ca08d0159a60 100644 --- a/runtime/queries/solidity/highlights.scm +++ b/runtime/queries/solidity/highlights.scm @@ -1,8 +1,3 @@ -; identifiers -; ----------- -(identifier) @variable -(yul_identifier) @variable - ; Pragma (pragma_directive) @tag (solidity_version_comparison_operator _ @tag) @@ -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) @@ -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 @@ -99,6 +95,7 @@ ; Keywords (meta_type_expression "type" @keyword) [ + "abstract" "pragma" "contract" "interface" @@ -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 @@ -217,3 +214,10 @@ "delete" "new" ] @keyword.operator + +; identifiers +; ----------- +((identifier) @variable.builtin + (#match? @variable.builtin "^(this|msg|block|tx)$")) +(identifier) @variable +(yul_identifier) @variable diff --git a/runtime/queries/solidity/textobjects.scm b/runtime/queries/solidity/textobjects.scm new file mode 100644 index 000000000000..4e5ffdd1207f --- /dev/null +++ b/runtime/queries/solidity/textobjects.scm @@ -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