mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 20:00:07 -04:00
Refactor solidity highlights.scm further
- Instead of @keyword, use @conditional, @exception, @return, @function as appropriate - Standardize to using @field (instead of @property)for struct members
This commit is contained in:
parent
8f3991065d
commit
fc0b881f93
2 changed files with 36 additions and 21 deletions
|
|
@ -32,7 +32,7 @@
|
||||||
(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)
|
||||||
; (struct_member name: (identifier) @field) ;; Technically correct, but makes highlight worst
|
(struct_member name: (identifier) @field)
|
||||||
(enum_declaration enum_type_name: (identifier) @type)
|
(enum_declaration enum_type_name: (identifier) @type)
|
||||||
; Color payable in payable address conversion as type and not as keyword
|
; Color payable in payable address conversion as type and not as keyword
|
||||||
(payable_conversion_expression "payable" @type)
|
(payable_conversion_expression "payable" @type)
|
||||||
|
|
@ -63,14 +63,15 @@
|
||||||
|
|
||||||
; Handles expressions like g();
|
; Handles expressions like g();
|
||||||
(call_expression . (identifier) @function)
|
(call_expression . (identifier) @function)
|
||||||
|
(function_definition
|
||||||
|
function_name: (identifier) @function)
|
||||||
|
|
||||||
; Handles the field in struct literals like MyStruct({MyField: MyVar * 2})
|
; Handles the field in struct literals like MyStruct({MyField: MyVar * 2})
|
||||||
(call_expression (identifier) @field . ":")
|
(call_expression (identifier) @field . ":")
|
||||||
|
|
||||||
; Function parameters
|
; Function parameters
|
||||||
(event_paramater name: (identifier) @parameter)
|
(event_paramater name: (identifier) @parameter)
|
||||||
(function_definition
|
(parameter name: (identifier) @parameter)
|
||||||
function_name: (identifier) @parameter)
|
|
||||||
|
|
||||||
; Yul functions
|
; Yul functions
|
||||||
(yul_function_call function: (yul_identifier) @function)
|
(yul_function_call function: (yul_identifier) @function)
|
||||||
|
|
@ -80,10 +81,10 @@
|
||||||
|
|
||||||
(meta_type_expression "type" @keyword)
|
(meta_type_expression "type" @keyword)
|
||||||
|
|
||||||
(member_expression (property_identifier) @property)
|
(member_expression (property_identifier) @field)
|
||||||
(property_identifier) @property
|
(property_identifier) @field
|
||||||
(struct_expression ((identifier) @property . ":"))
|
(struct_expression ((identifier) @field . ":"))
|
||||||
(enum_value) @property
|
(enum_value) @constant
|
||||||
|
|
||||||
|
|
||||||
; Keywords
|
; Keywords
|
||||||
|
|
@ -98,16 +99,6 @@
|
||||||
"event"
|
"event"
|
||||||
"using"
|
"using"
|
||||||
"assembly"
|
"assembly"
|
||||||
"switch"
|
|
||||||
"case"
|
|
||||||
"default"
|
|
||||||
"break"
|
|
||||||
"continue"
|
|
||||||
"if"
|
|
||||||
"else"
|
|
||||||
"try"
|
|
||||||
"catch"
|
|
||||||
"return"
|
|
||||||
"emit"
|
"emit"
|
||||||
"public"
|
"public"
|
||||||
"internal"
|
"internal"
|
||||||
|
|
@ -117,11 +108,9 @@
|
||||||
"view"
|
"view"
|
||||||
"payable"
|
"payable"
|
||||||
"modifier"
|
"modifier"
|
||||||
"returns"
|
|
||||||
"memory"
|
"memory"
|
||||||
"storage"
|
"storage"
|
||||||
"calldata"
|
"calldata"
|
||||||
"function"
|
|
||||||
"var"
|
"var"
|
||||||
(constant)
|
(constant)
|
||||||
(virtual)
|
(virtual)
|
||||||
|
|
@ -135,6 +124,28 @@
|
||||||
"do"
|
"do"
|
||||||
] @repeat
|
] @repeat
|
||||||
|
|
||||||
|
[
|
||||||
|
"break"
|
||||||
|
"continue"
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"switch"
|
||||||
|
"case"
|
||||||
|
"default"
|
||||||
|
] @conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"try"
|
||||||
|
"catch"
|
||||||
|
] @exception
|
||||||
|
|
||||||
|
[
|
||||||
|
"return"
|
||||||
|
"returns"
|
||||||
|
] @keyword.return
|
||||||
|
|
||||||
|
"function" @keyword.function
|
||||||
|
|
||||||
"import" @include
|
"import" @include
|
||||||
(import_directive "as" @include)
|
(import_directive "as" @include)
|
||||||
(import_directive "from" @include)
|
(import_directive "from" @include)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ contract Ballot {
|
||||||
// ^ type
|
// ^ type
|
||||||
uint weight; // weight is accumulated by delegation
|
uint weight; // weight is accumulated by delegation
|
||||||
// ^ type
|
// ^ type
|
||||||
// ^ variable
|
// ^ field
|
||||||
bool voted; // if true, that person already voted
|
bool voted; // if true, that person already voted
|
||||||
address delegate; // person delegated to
|
address delegate; // person delegated to
|
||||||
uint vote; // index of the voted proposal
|
uint vote; // index of the voted proposal
|
||||||
|
|
@ -45,6 +45,9 @@ contract Ballot {
|
||||||
// A dynamically-sized array of `Proposal` structs.
|
// A dynamically-sized array of `Proposal` structs.
|
||||||
Proposal[] public proposals;
|
Proposal[] public proposals;
|
||||||
|
|
||||||
|
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
|
||||||
|
// ^ constant
|
||||||
|
|
||||||
/// Create a new ballot to choose one of `proposalNames`.
|
/// Create a new ballot to choose one of `proposalNames`.
|
||||||
constructor(bytes32[] memory proposalNames) {
|
constructor(bytes32[] memory proposalNames) {
|
||||||
// ^ constructor
|
// ^ constructor
|
||||||
|
|
@ -69,8 +72,9 @@ contract Ballot {
|
||||||
// Give `voter` the right to vote on this ballot.
|
// Give `voter` the right to vote on this ballot.
|
||||||
// May only be called by `chairperson`.
|
// May only be called by `chairperson`.
|
||||||
function giveRightToVote(address voter) external {
|
function giveRightToVote(address voter) external {
|
||||||
// ^ keyword
|
// ^ keyword.function
|
||||||
// ^ function
|
// ^ function
|
||||||
|
// ^ parameter
|
||||||
// If the first argument of `require` evaluates
|
// If the first argument of `require` evaluates
|
||||||
// to `false`, execution terminates and all
|
// to `false`, execution terminates and all
|
||||||
// changes to the state and to Ether balances
|
// changes to the state and to Ether balances
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue