What happened?
Problem
Test runnables (the ▶ play buttons next to @Test methods and test classes) don't appear for Java files in simple (non-dotted) packages like package org;. They only work for dotted package names like package com.example;.
Root Cause
The runnables.scm test queries require (scoped_identifier) as the child of package_declaration:
; Run test function (marker annotation, e.g. @Test)
((package_declaration
(scoped_identifier) @java_package_name) ; <-- this is the problem
(class_declaration
...
(#match? @annotation_name "Test$")))) @_
(#set! tag java-test-method))
In the tree-sitter-java grammar, package_declaration uses _name, which is inlined and resolves to either identifier (for simple names like org) or scoped_identifier (for dotted names like com.example):
package org; → (package_declaration (identifier))
package com.example; → (package_declaration (scoped_identifier (identifier) (identifier)))
The query only matches the latter, so any test in a simple package gets no runnable.
Note that the main method query already handles this correctly by making the package_declaration optional with ?:
((package_declaration
(scoped_identifier) @java_package_name)? ; <-- optional, works with or without package
(class_declaration
...
Fix
All test runnable patterns that match (package_declaration (scoped_identifier) ...) should also match (package_declaration (identifier) ...):
(package_declaration
[
(scoped_identifier) @java_package_name
(identifier) @java_package_name
])
This affects the following patterns:
java-test-method
java-test-method-nested
java-test-class
java-test-class-nested
Alternatively, making the package_declaration optional (like the main method queries do with ?) would also fix the issue and additionally handle classes in the default package.
Reproduction
- Create a Java file with a simple package:
package org;
- Add a
@Test annotated method
- Observe that no ▶ launcher appears in Zed
- Change the package to
package com.example; and observe the launcher appears
Environment
- Zed Java extension version: 6.8.16
- JDTLS: 1.58.0
- Java: 25
What did you expect to happen?
To have a test runnable (arrow) launcher in the unit tests without caring of the package of the class.
Environment
Zed: 1.1.6
Platform: macOS Tahoe 26.4.1.4
Zed Java extension version: 6.8.16
JDTLS: 1.58.0
Java: 25
What happened?
Problem
Test runnables (the ▶ play buttons next to
@Testmethods and test classes) don't appear for Java files in simple (non-dotted) packages likepackage org;. They only work for dotted package names likepackage com.example;.Root Cause
The
runnables.scmtest queries require(scoped_identifier)as the child ofpackage_declaration:In the tree-sitter-java grammar,
package_declarationuses_name, which is inlined and resolves to eitheridentifier(for simple names likeorg) orscoped_identifier(for dotted names likecom.example):package org;→(package_declaration (identifier))package com.example;→(package_declaration (scoped_identifier (identifier) (identifier)))The query only matches the latter, so any test in a simple package gets no runnable.
Note that the main method query already handles this correctly by making the
package_declarationoptional with?:((package_declaration (scoped_identifier) @java_package_name)? ; <-- optional, works with or without package (class_declaration ...Fix
All test runnable patterns that match
(package_declaration (scoped_identifier) ...)should also match(package_declaration (identifier) ...):(package_declaration [ (scoped_identifier) @java_package_name (identifier) @java_package_name ])This affects the following patterns:
java-test-methodjava-test-method-nestedjava-test-classjava-test-class-nestedAlternatively, making the
package_declarationoptional (like the main method queries do with?) would also fix the issue and additionally handle classes in the default package.Reproduction
package org;@Testannotated methodpackage com.example;and observe the launcher appearsEnvironment
What did you expect to happen?
To have a test runnable (arrow) launcher in the unit tests without caring of the package of the class.
Environment
Zed: 1.1.6
Platform: macOS Tahoe 26.4.1.4
Zed Java extension version: 6.8.16
JDTLS: 1.58.0
Java: 25