diff options
| author | YongJieYongJie <KhooYongJie@gmx.com> | 2022-03-11 05:07:26 +0800 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-03-11 19:06:39 +0100 |
| commit | 8f3991065d4753c4b458fb19b9a2332f3d740c50 (patch) | |
| tree | 2e7b65db6c6203374b69fb6d693cdc652eca810d | |
| parent | Add highlights query for Solidity (diff) | |
| download | nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar.gz nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar.bz2 nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar.lz nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar.xz nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.tar.zst nvim-treesitter-8f3991065d4753c4b458fb19b9a2332f3d740c50.zip | |
Refactor solidity highlights.scm
- Use more specific/appropriate captures; change invalid captures
- Don't highlight punctuations in type names (e.g., the brackets in
'bytes32[]')
| -rw-r--r-- | queries/solidity/highlights.scm | 36 | ||||
| -rw-r--r-- | tests/query/highlights/solidity/test.sol | 9 |
2 files changed, 31 insertions, 14 deletions
diff --git a/queries/solidity/highlights.scm b/queries/solidity/highlights.scm index 2081db8df..14fd6c528 100644 --- a/queries/solidity/highlights.scm +++ b/queries/solidity/highlights.scm @@ -27,7 +27,8 @@ ; Type -(type_name) @type +(type_name (identifier) @type) +(type_name "mapping" @type) (primitive_type) @type (contract_declaration name: (identifier) @type) (struct_declaration struct_name: (identifier) @type) @@ -58,7 +59,7 @@ (modifier_invocation (identifier) @function) ; Handles expressions like structVariable.g(); -(call_expression . (member_expression (property_identifier) @function.method)) +(call_expression . (member_expression (property_identifier) @method)) ; Handles expressions like g(); (call_expression . (identifier) @function) @@ -67,15 +68,15 @@ (call_expression (identifier) @field . ":") ; Function parameters -(event_paramater name: (identifier) @variable.parameter) +(event_paramater name: (identifier) @parameter) (function_definition - function_name: (identifier) @variable.parameter) + function_name: (identifier) @parameter) ; Yul functions (yul_function_call function: (yul_identifier) @function) ; Yul function parameters -(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter) +(yul_function_definition . (yul_identifier) @function (yul_identifier) @parameter) (meta_type_expression "type" @keyword) @@ -88,7 +89,6 @@ ; Keywords [ "pragma" - "import" "contract" "interface" "library" @@ -105,9 +105,6 @@ "continue" "if" "else" - "for" - "while" - "do" "try" "catch" "return" @@ -132,8 +129,16 @@ (yul_leave) ] @keyword -(import_directive "as" @keyword) -(import_directive "from" @keyword) +[ + "for" + "while" + "do" +] @repeat + +"import" @include +(import_directive "as" @include) +(import_directive "from" @include) + (event_paramater "indexed" @keyword) ; Punctuation @@ -145,7 +150,7 @@ "]" "{" "}" -] @punctuation.bracket +] @punctuation.bracket [ @@ -182,12 +187,15 @@ "~" "-" "+" - "delete" - "new" "++" "--" ] @operator +[ + "delete" + "new" +] @keyword.operator + (identifier) @variable (yul_identifier) @variable diff --git a/tests/query/highlights/solidity/test.sol b/tests/query/highlights/solidity/test.sol index 8781b60ed..aadf11b6d 100644 --- a/tests/query/highlights/solidity/test.sol +++ b/tests/query/highlights/solidity/test.sol @@ -5,6 +5,10 @@ pragma solidity >=0.7.0 <0.9.0; // ^ keyword // ^ tag + +import * as something from "anotherFile"; +// ^ ^ ^ include + /// @title Voting with delegation. // ^ attribute contract Ballot { @@ -170,4 +174,9 @@ contract Ballot { } } +contract Another { + Ballot b = new Ballot(new bytes32[](1)); +// ^ keyword.operator +} + // vim:ft=solidity |
