mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
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[]')
This commit is contained in:
parent
a180859eea
commit
8f3991065d
2 changed files with 31 additions and 14 deletions
|
|
@ -27,7 +27,8 @@
|
||||||
|
|
||||||
|
|
||||||
; Type
|
; Type
|
||||||
(type_name) @type
|
(type_name (identifier) @type)
|
||||||
|
(type_name "mapping" @type)
|
||||||
(primitive_type) @type
|
(primitive_type) @type
|
||||||
(contract_declaration name: (identifier) @type)
|
(contract_declaration name: (identifier) @type)
|
||||||
(struct_declaration struct_name: (identifier) @type)
|
(struct_declaration struct_name: (identifier) @type)
|
||||||
|
|
@ -58,7 +59,7 @@
|
||||||
(modifier_invocation (identifier) @function)
|
(modifier_invocation (identifier) @function)
|
||||||
|
|
||||||
; Handles expressions like structVariable.g();
|
; Handles expressions like structVariable.g();
|
||||||
(call_expression . (member_expression (property_identifier) @function.method))
|
(call_expression . (member_expression (property_identifier) @method))
|
||||||
|
|
||||||
; Handles expressions like g();
|
; Handles expressions like g();
|
||||||
(call_expression . (identifier) @function)
|
(call_expression . (identifier) @function)
|
||||||
|
|
@ -67,15 +68,15 @@
|
||||||
(call_expression (identifier) @field . ":")
|
(call_expression (identifier) @field . ":")
|
||||||
|
|
||||||
; Function parameters
|
; Function parameters
|
||||||
(event_paramater name: (identifier) @variable.parameter)
|
(event_paramater name: (identifier) @parameter)
|
||||||
(function_definition
|
(function_definition
|
||||||
function_name: (identifier) @variable.parameter)
|
function_name: (identifier) @parameter)
|
||||||
|
|
||||||
; Yul functions
|
; Yul functions
|
||||||
(yul_function_call function: (yul_identifier) @function)
|
(yul_function_call function: (yul_identifier) @function)
|
||||||
|
|
||||||
; Yul function parameters
|
; 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)
|
(meta_type_expression "type" @keyword)
|
||||||
|
|
||||||
|
|
@ -88,7 +89,6 @@
|
||||||
; Keywords
|
; Keywords
|
||||||
[
|
[
|
||||||
"pragma"
|
"pragma"
|
||||||
"import"
|
|
||||||
"contract"
|
"contract"
|
||||||
"interface"
|
"interface"
|
||||||
"library"
|
"library"
|
||||||
|
|
@ -105,9 +105,6 @@
|
||||||
"continue"
|
"continue"
|
||||||
"if"
|
"if"
|
||||||
"else"
|
"else"
|
||||||
"for"
|
|
||||||
"while"
|
|
||||||
"do"
|
|
||||||
"try"
|
"try"
|
||||||
"catch"
|
"catch"
|
||||||
"return"
|
"return"
|
||||||
|
|
@ -132,8 +129,16 @@
|
||||||
(yul_leave)
|
(yul_leave)
|
||||||
] @keyword
|
] @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)
|
(event_paramater "indexed" @keyword)
|
||||||
|
|
||||||
; Punctuation
|
; Punctuation
|
||||||
|
|
@ -145,7 +150,7 @@
|
||||||
"]"
|
"]"
|
||||||
"{"
|
"{"
|
||||||
"}"
|
"}"
|
||||||
] @punctuation.bracket
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
@ -182,12 +187,15 @@
|
||||||
"~"
|
"~"
|
||||||
"-"
|
"-"
|
||||||
"+"
|
"+"
|
||||||
"delete"
|
|
||||||
"new"
|
|
||||||
"++"
|
"++"
|
||||||
"--"
|
"--"
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"delete"
|
||||||
|
"new"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
(identifier) @variable
|
(identifier) @variable
|
||||||
(yul_identifier) @variable
|
(yul_identifier) @variable
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@
|
||||||
pragma solidity >=0.7.0 <0.9.0;
|
pragma solidity >=0.7.0 <0.9.0;
|
||||||
// ^ keyword
|
// ^ keyword
|
||||||
// ^ tag
|
// ^ tag
|
||||||
|
|
||||||
|
import * as something from "anotherFile";
|
||||||
|
// ^ ^ ^ include
|
||||||
|
|
||||||
/// @title Voting with delegation.
|
/// @title Voting with delegation.
|
||||||
// ^ attribute
|
// ^ attribute
|
||||||
contract Ballot {
|
contract Ballot {
|
||||||
|
|
@ -170,4 +174,9 @@ contract Ballot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contract Another {
|
||||||
|
Ballot b = new Ballot(new bytes32[](1));
|
||||||
|
// ^ keyword.operator
|
||||||
|
}
|
||||||
|
|
||||||
// vim:ft=solidity
|
// vim:ft=solidity
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue