tasks: Provide task variables from matching runnable ranges in task modal (#12237)

In #12003 we found ourselves in need for precise region tracking in
which a given runnable has an effect in order to grab variables from it.
This PR makes it so that in task modal all task variables from queries
overlapping current cursor position.
However, in the process of working on that I've found that we cannot
always use a top-level capture to represent the full match range of
runnable (which has been my assumption up to this point). Tree-sitter
captures cannot capture sibling groups; we did just that in Rust
queries.

Thankfully, none of the extensions are affected as in them, a capture is
always attached to single node. This PR adds annotations to them
nonetheless; we'll be able to get rid of top-level captures in extension
runnables.scm once this PR is in stable version of Zed.


Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-05-24 21:00:23 +02:00 committed by GitHub
parent 08a3d3a0c2
commit 27229bba6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 295 additions and 183 deletions

View file

@ -2,87 +2,101 @@
; and that doesn't have the abstract modifier
; and have a method that follow the naming convention of PHPUnit test methods
; and the method is public
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
(method_declaration
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#match? @run "^test.*")
(
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
(method_declaration
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#match? @run "^test.*")
)
)
)
) @phpunit-test
) @phpunit-test
(#set! tag phpunit-test)
)
; Class that follow the naming convention of PHPUnit test classes
; and that doesn't have the abstract modifier
; and have a method that has the @test annotation
; and the method is public
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
((comment) @_comment
(#match? @_comment ".*@test\\b.*")
.
(method_declaration
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#not-match? @run "^test.*")
))
)
) @phpunit-test
(
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
((comment) @_comment
(#match? @_comment ".*@test\\b.*")
.
(method_declaration
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#not-match? @run "^test.*")
))
)
) @phpunit-test
(#set! tag phpunit-test)
)
; Class that follow the naming convention of PHPUnit test classes
; and that doesn't have the abstract modifier
; and have a method that has the #[Test] attribute
; and the method is public
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
(method_declaration
(attribute_list
(attribute_group
(attribute (name) @_attribute)
(
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @_name
(#match? @_name ".*Test$")
body: (declaration_list
(method_declaration
(attribute_list
(attribute_group
(attribute (name) @_attribute)
)
)
(#eq? @_attribute "Test")
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#not-match? @run "^test.*")
)
(#eq? @_attribute "Test")
(visibility_modifier)? @_visibility
(#eq? @_visibility "public")
name: (_) @run
(#not-match? @run "^test.*")
)
)
) @phpunit-test
) @phpunit-test
(#set! tag phpunit-test)
)
; Class that follow the naming convention of PHPUnit test classes
; and that doesn't have the abstract modifier
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @run
(#match? @run ".*Test$")
) @phpunit-test
(
(class_declaration
modifier: (_)? @_modifier
(#not-eq? @_modifier "abstract")
name: (_) @run
(#match? @run ".*Test$")
) @phpunit-test
(#set! tag phpunit-test)
)
; Add support for Pest runnable
; Function expression that has `it`, `test` or `describe` as the function name
(function_call_expression
function: (_) @_name
(#any-of? @_name "it" "test" "describe")
arguments: (arguments
.
(argument
(encapsed_string (string_value) @run)
(
(function_call_expression
function: (_) @_name
(#any-of? @_name "it" "test" "describe")
arguments: (arguments
.
(argument
(encapsed_string (string_value) @run)
)
)
)
) @pest-test
) @pest-test
(#set! tag pest-test)
)