fix: detect PHPUnit #[Test] attribute with fully-qualified name#121
Open
zoispag wants to merge 1 commit into
Open
fix: detect PHPUnit #[Test] attribute with fully-qualified name#121zoispag wants to merge 1 commit into
zoispag wants to merge 1 commit into
Conversation
Extends the phpunit-test runnable query to also match methods annotated
with a fully-qualified attribute such as:
#[\PHPUnit\Framework\Attributes\Test]
Previously only the short form `#[Test]` was matched, because the query
only handled `(attribute (name))`. For a FQDN attribute the tree-sitter
node is a `qualified_name` whose direct `name` child is the class name
("Test"); the namespace segments live inside the nested `prefix` field
and are not matched.
The fix adds an alternative branch `(qualified_name (name) @_attribute)`
alongside the existing `(name) @_attribute` inside the attribute match,
so both forms produce the gutter play button.
|
We require contributors to sign our Contributor License Agreement, and we don't have @zoispag on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
Author
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a PHPUnit test method is annotated with the fully-qualified attribute form:
Zed does not show the ▷ gutter play button, so the test cannot be run from the editor. Only the short imported form
#[Test]triggers the runnable.Root cause
The
runnables.scmquery for the#[Test]case only matches a simplenamenode inside theattribute:(attribute (name) @_attribute) (#eq? @_attribute "Test")For a fully-qualified attribute, the tree-sitter PHP grammar produces a
qualified_namenode instead of a barename. According to the grammar definition,qualified_namehas the structure:The namespace segments (
PHPUnit,Framework,Attributes) are nested inside theprefixfield, while the class name (Test) is a directnamechild ofqualified_name. The existing query never reaches this node.Fix
Add an alternative branch
(qualified_name (name) @_attribute)inside the attribute match so both the short and fully-qualified forms are handled:(attribute [ (name) @_attribute (qualified_name (name) @_attribute) ] ) (#eq? @_attribute "Test")This covers:
#[Test]— short form (existing, unchanged)#[PHPUnit\Framework\Attributes\Test]— relative qualified form#[\PHPUnit\Framework\Attributes\Test]— fully-qualified form (global namespace prefix)