Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ crate-type = ["cdylib"]
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
zed_extension_api = "0.6.0"

[dev-dependencies]
tree-sitter = "0.25"
tree-sitter-swift = "0.7"
streaming-iterator = "0.1"
41 changes: 40 additions & 1 deletion languages/swift/runnables.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
;;
;; While the tasks defined in this extension don't care which library is used,
;; other tasks built by users might.
;;
;; INDIRECT XCTEST SUBCLASSES:
;; Tree-sitter queries cannot follow inheritance chains semantically, so indirect
;; subclasses (MyTests <- MyTestsBase <- XCTestCase) are not automatically detected.
;;
;; WORKAROUND: Add a // @XCTestClass comment before indirect subclass declarations:
;;
;; class MyTestsBase: XCTestCase { }
;;
;; // @XCTestClass
;; class MyTests: MyTestsBase {
;; func testSomething() { }
;; }
;;
;; This allows the query to recognize and run tests in indirect subclasses.

;; @Suite struct/class
(
Expand Down Expand Up @@ -88,6 +103,30 @@
(#set! tag swift-xctest-func)
)

;; XCTestCase indirect subclass with @XCTestClass comment annotation
;; This pattern allows users to mark indirect subclasses (MyTests <- MyTestsBase <- XCTestCase)
;; by adding a "// @XCTestClass" comment before the class declaration.
(
(comment) @_marker (#match? @_marker ".*@XCTestClass.*")
(class_declaration
name: (type_identifier) @SWIFT_TEST_CLASS @run
) @_swift-xctest-class
(#set! tag swift-xctest-class)
)

;; Test function within comment-annotated XCTest class
(
(comment) @_marker (#match? @_marker ".*@XCTestClass.*")
(class_declaration
name: (type_identifier) @SWIFT_TEST_CLASS
body: (class_body
(function_declaration
name: (simple_identifier) @_name @SWIFT_TEST_FUNC @run (#match? @run "^test")
)
)
) @_swift-xctest-func
(#set! tag swift-xctest-func)
)

;; QuickSpec subclass
(
Expand All @@ -113,4 +152,4 @@
)
) @_swift-test-async-spec
(#set! tag swift-test-async-spec)
)
)
Loading