Skip to content

Commit

Permalink
tasks: Provide task variables from matching runnable ranges in task m…
Browse files Browse the repository at this point in the history
…odal (zed-industries/zed#12237)

In zed-industries/zed#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
  • Loading branch information
osiewicz authored May 24, 2024
1 parent 48c83e9 commit 481ea91
Showing 1 changed file with 52 additions and 31 deletions.
83 changes: 52 additions & 31 deletions languages/ruby/runnables.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,67 @@

; Minitest
;; Rails unit tests
(class
name: [
(constant) @run
(scope_resolution scope: (constant) name: (constant) @run)
]
(superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase)$"))
) @minitest-test

(call
method: (identifier) @run (#eq? @run "test")
arguments: (argument_list (string (string_content) @name))
) @minitest-test
(
(class
name: [
(constant) @run
(scope_resolution scope: (constant) name: (constant) @run)
]
(superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase)$"))
) @minitest-test
(#set! tag minitest-test)
)

(
(call
method: (identifier) @run (#eq? @run "test")
arguments: (argument_list (string (string_content) @name))
) @minitest-test
(#set! tag minitest-test)
)

; Methods that begin with test_
(method
name: (identifier) @run (#match? @run "^test_")
) @minitest-test
(
(method
name: (identifier) @run (#match? @run "^test_")
) @minitest-test
(#set! tag minitest-test)
)

; System tests that inherit from ApplicationSystemTestCase
(class
name: (constant) @run (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$")
) @minitest-test
(
(class
name: (constant) @run (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$")
) @minitest-test
(#set! tag minitest-test)
)

; RSpec

; Example groups with literals
(call
method: (identifier) @run (#any-of? @run "describe" "context")
arguments: (argument_list . (_) @name)
) @rspec-test
(
(call
method: (identifier) @run (#any-of? @run "describe" "context")
arguments: (argument_list . (_) @name)
) @rspec-test
(#set! tag rspec-test)
)

; Examples
(call
method: (identifier) @run (#any-of? @run "it" "its" "specify")
arguments: (argument_list (string (string_content) @name))
) @rspec-test
(
(call
method: (identifier) @run (#any-of? @run "it" "its" "specify")
arguments: (argument_list (string (string_content) @name))
) @rspec-test
(#set! tag rspec-test)
)

; Examples (one-liner syntax)
(call
method: (identifier) @run (#any-of? @run "it" "its" "specify")
block: (_) @name
!arguments
) @rspec-test
(
(call
method: (identifier) @run (#any-of? @run "it" "its" "specify")
block: (_) @name
!arguments
) @rspec-test
(#set! tag rspec-test)
)

0 comments on commit 481ea91

Please sign in to comment.