mirror of https://github.com/helix-editor/helix
queries: `bar` in `foo::bar` is always a function when passed as arg
parent
42db29a32d
commit
b5a07f9974
|
@ -310,30 +310,37 @@
|
||||||
; Functions
|
; Functions
|
||||||
; -------
|
; -------
|
||||||
|
|
||||||
; Special handling for point-free functions passed to some "well-known"
|
; highlight `baz` in `any_function(foo::bar::baz)` as function
|
||||||
; methods, that are known to take a closure as the first argument
|
; This generically works for an unlimited number of path segments:
|
||||||
;
|
;
|
||||||
; For example, these are @function:
|
; - `f(foo::bar)`
|
||||||
|
; - `f(foo::bar::baz)`
|
||||||
|
; - `f(foo::bar::baz::quux)`
|
||||||
;
|
;
|
||||||
; - `foo` in `a.map(foo)`
|
; We know that in the above examples, the last component of each path is a function
|
||||||
; - `bar` in `a.map(foo::bar)`
|
; as the only other valid thing (following Rust naming conventions) would be a module at
|
||||||
; - `baz` in `a.map(foo::bar::baz)`
|
; that position, however you cannot pass modules as arguments
|
||||||
|
(call_expression
|
||||||
|
function: _
|
||||||
|
arguments: (arguments "("
|
||||||
|
(scoped_identifier
|
||||||
|
path: _
|
||||||
|
name: (identifier) @function) ")"))
|
||||||
|
|
||||||
|
; Special handling for point-free functions that are not part of a path
|
||||||
|
; but are just passed as variables to some "well-known"
|
||||||
|
; methods, which are known to take a closure as the first argument
|
||||||
|
;
|
||||||
|
; For example, `foo` in `a.map(foo)` is a @function
|
||||||
(call_expression
|
(call_expression
|
||||||
function: (field_expression
|
function: (field_expression
|
||||||
value: _
|
value: _
|
||||||
field: (field_identifier) @_method_name)
|
field: (field_identifier) @_method_name)
|
||||||
arguments: [
|
arguments:
|
||||||
; handles `a.map(foo)`
|
; first argument is `@function`
|
||||||
(arguments "("
|
(arguments "("
|
||||||
.
|
.
|
||||||
(identifier) @function ")")
|
(identifier) @function)
|
||||||
; `a.map(foo::bar)`, `a.map(foo::bar::baz)`... (unlimited path segments)
|
|
||||||
(arguments "("
|
|
||||||
.
|
|
||||||
(scoped_identifier
|
|
||||||
path: _
|
|
||||||
name: (identifier) @function) ")")
|
|
||||||
]
|
|
||||||
(#any-of? @_method_name
|
(#any-of? @_method_name
|
||||||
; methods on `core::iter::Iterator`
|
; methods on `core::iter::Iterator`
|
||||||
"map" "map_while" "filter_map" "flat_map" "map_windows"
|
"map" "map_while" "filter_map" "flat_map" "map_windows"
|
||||||
|
@ -411,22 +418,15 @@
|
||||||
function: (field_expression
|
function: (field_expression
|
||||||
value: _
|
value: _
|
||||||
field: (field_identifier) @_method_name)
|
field: (field_identifier) @_method_name)
|
||||||
arguments: [
|
arguments:
|
||||||
; handles `a.map_or_else(..., foo)`
|
; handles `a.map_or_else(..., foo)`
|
||||||
(arguments "("
|
(arguments "("
|
||||||
; first argument is ignored
|
; first argument is ignored
|
||||||
.
|
.
|
||||||
_
|
_
|
||||||
|
.
|
||||||
|
; second argument is @function
|
||||||
(identifier) @function ")")
|
(identifier) @function ")")
|
||||||
; `a.map_or_else(..., foo::bar)`, `a.map(..., foo::bar::baz)`... (unlimited path segments)
|
|
||||||
(arguments "("
|
|
||||||
; first argument is ignored
|
|
||||||
.
|
|
||||||
_
|
|
||||||
(scoped_identifier
|
|
||||||
path: _
|
|
||||||
name: (identifier) @function) ")")
|
|
||||||
]
|
|
||||||
(#any-of? @_method_name
|
(#any-of? @_method_name
|
||||||
; methods on `Option`
|
; methods on `Option`
|
||||||
"map_or_else" "zip_with"
|
"map_or_else" "zip_with"
|
||||||
|
|
Loading…
Reference in New Issue