tree-sitter-solidity: Use upstream, update queries
This commit is contained in:
parent
44b447947c
commit
20ed8c2595
3 changed files with 92 additions and 53 deletions
|
@ -1192,7 +1192,7 @@ language-server = { command = "solc", args = ["--lsp"] }
|
|||
|
||||
[[grammar]]
|
||||
name = "solidity"
|
||||
source = { git = "https://github.com/slinlee/tree-sitter-solidity", rev = "f3a002274744e859bf64cf3524985f8c31ea84fd" }
|
||||
source = { git = "https://github.com/JoranHonig/tree-sitter-solidity", rev = "9004b86531cb424bd379424cf7266a4585f2af7d" }
|
||||
|
||||
[[language]]
|
||||
name = "gleam"
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
(comment) @comment
|
||||
; identifiers
|
||||
; -----------
|
||||
(identifier) @variable
|
||||
(yul_identifier) @variable
|
||||
|
||||
; Pragma
|
||||
(pragma_directive) @tag
|
||||
(solidity_version_comparison_operator ">=" @tag)
|
||||
(solidity_version_comparison_operator "<=" @tag)
|
||||
(solidity_version_comparison_operator "=" @tag)
|
||||
(solidity_version_comparison_operator "~" @tag)
|
||||
(solidity_version_comparison_operator "^" @tag)
|
||||
(solidity_version_comparison_operator _ @tag)
|
||||
|
||||
|
||||
; Literals
|
||||
; --------
|
||||
|
||||
[
|
||||
(string)
|
||||
(hex_string_literal)
|
||||
|
@ -26,26 +27,38 @@
|
|||
(false)
|
||||
] @constant.builtin
|
||||
|
||||
(comment) @comment
|
||||
|
||||
|
||||
; Definitions and references
|
||||
; -----------
|
||||
|
||||
; Type
|
||||
(type_name) @type
|
||||
(primitive_type) @type
|
||||
(struct_declaration struct_name: (identifier) @type)
|
||||
(enum_declaration enum_type_name: (identifier) @type)
|
||||
(user_defined_type (identifier) @type)
|
||||
|
||||
; Color payable in payable address conversion as type and not as keyword
|
||||
(payable_conversion_expression "payable" @type)
|
||||
(emit_statement . (identifier) @type)
|
||||
; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {}
|
||||
(override_specifier (identifier) @type)
|
||||
; Ensures that delimiters in mapping( ... => .. ) are not colored like types
|
||||
(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)
|
||||
|
||||
|
||||
|
||||
; Functions and parameters
|
||||
; Definitions
|
||||
(struct_declaration
|
||||
name: (identifier) @type)
|
||||
(enum_declaration
|
||||
name: (identifier) @type)
|
||||
(contract_declaration
|
||||
name: (identifier) @type)
|
||||
(library_declaration
|
||||
name: (identifier) @type)
|
||||
(interface_declaration
|
||||
name: (identifier) @type)
|
||||
(event_definition
|
||||
name: (identifier) @type)
|
||||
|
||||
(function_definition
|
||||
function_name: (identifier) @function)
|
||||
name: (identifier) @function)
|
||||
|
||||
(modifier_definition
|
||||
name: (identifier) @function)
|
||||
(yul_evm_builtin) @function.builtin
|
||||
|
@ -55,37 +68,38 @@
|
|||
(fallback_receive_definition "receive" @constructor)
|
||||
(fallback_receive_definition "fallback" @constructor)
|
||||
|
||||
(struct_member name: (identifier) @variable.other.member)
|
||||
(enum_value) @constant
|
||||
|
||||
; Invocations
|
||||
(emit_statement . (identifier) @type)
|
||||
(modifier_invocation (identifier) @function)
|
||||
|
||||
; Handles expressions like structVariable.g();
|
||||
(call_expression . (member_expression (property_identifier) @function.method))
|
||||
|
||||
; Handles expressions like g();
|
||||
(call_expression . (member_expression property: (identifier) @function.method))
|
||||
(call_expression . (identifier) @function)
|
||||
|
||||
; Function parameters
|
||||
(event_paramater name: (identifier) @variable.parameter) ; TODO fix spelling once fixed upstream
|
||||
(function_definition
|
||||
function_name: (identifier) @variable.parameter)
|
||||
(call_struct_argument name: (identifier) @field)
|
||||
(event_paramater name: (identifier) @variable.parameter)
|
||||
(parameter name: (identifier) @variable.parameter)
|
||||
|
||||
; Yul functions
|
||||
(yul_function_call function: (yul_identifier) @function)
|
||||
|
||||
; Yul function parameters
|
||||
(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter)
|
||||
|
||||
(meta_type_expression "type" @keyword)
|
||||
|
||||
(member_expression (property_identifier) @variable.other.member)
|
||||
(property_identifier) @variable.other.member
|
||||
(struct_expression ((identifier) @variable.other.member . ":"))
|
||||
(enum_value) @variable.other.member
|
||||
; Structs and members
|
||||
(member_expression property: (identifier) @variable.other.member)
|
||||
(struct_expression type: ((identifier) @type .))
|
||||
(struct_field_assignment name: (identifier) @variable.other.member)
|
||||
|
||||
; Tokens
|
||||
; -------
|
||||
|
||||
; Keywords
|
||||
(meta_type_expression "type" @keyword)
|
||||
[
|
||||
"pragma"
|
||||
"import"
|
||||
"contract"
|
||||
"interface"
|
||||
"library"
|
||||
|
@ -95,19 +109,6 @@
|
|||
"event"
|
||||
"using"
|
||||
"assembly"
|
||||
"switch"
|
||||
"case"
|
||||
"default"
|
||||
"break"
|
||||
"continue"
|
||||
"if"
|
||||
"else"
|
||||
"for"
|
||||
"while"
|
||||
"do"
|
||||
"try"
|
||||
"catch"
|
||||
"return"
|
||||
"emit"
|
||||
"public"
|
||||
"internal"
|
||||
|
@ -117,20 +118,47 @@
|
|||
"view"
|
||||
"payable"
|
||||
"modifier"
|
||||
"returns"
|
||||
"memory"
|
||||
"storage"
|
||||
"calldata"
|
||||
"function"
|
||||
"var"
|
||||
(constant)
|
||||
"constant"
|
||||
(virtual)
|
||||
(override_specifier)
|
||||
(yul_leave)
|
||||
] @keyword
|
||||
|
||||
(import_directive "as" @keyword)
|
||||
(import_directive "from" @keyword)
|
||||
[
|
||||
"for"
|
||||
"while"
|
||||
"do"
|
||||
] @keyword.control.repeat
|
||||
|
||||
[
|
||||
"break"
|
||||
"continue"
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
"case"
|
||||
"default"
|
||||
] @keyword.control.conditional
|
||||
|
||||
[
|
||||
"try"
|
||||
"catch"
|
||||
] @keyword.control.exception
|
||||
|
||||
[
|
||||
"return"
|
||||
"returns"
|
||||
] @keyword.control.return
|
||||
|
||||
"function" @keyword.function
|
||||
|
||||
"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
|
||||
|
||||
; Punctuation
|
||||
|
@ -142,7 +170,7 @@
|
|||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
] @punctuation.bracket
|
||||
|
||||
|
||||
[
|
||||
|
@ -185,5 +213,7 @@
|
|||
"--"
|
||||
] @operator
|
||||
|
||||
(identifier) @variable
|
||||
(yul_identifier) @variable
|
||||
[
|
||||
"delete"
|
||||
"new"
|
||||
] @keyword.operator
|
||||
|
|
9
runtime/queries/solidity/locals.scm
Normal file
9
runtime/queries/solidity/locals.scm
Normal file
|
@ -0,0 +1,9 @@
|
|||
(function_definition) @local.scope
|
||||
(block_statement) @local.scope
|
||||
|
||||
(function_definition (parameter name: (identifier) @local.definition))
|
||||
|
||||
; still have to support tuple assignments
|
||||
(assignment_expression left: (identifier) @local.definition)
|
||||
|
||||
(identifier) @local.reference
|
Loading…
Reference in a new issue