Repository navigation
fix(parsers): capture PHP imports instead of trait uses - #1563
Merged
Merged
Conversation
The imports query captured `use_declaration`, which in tree-sitter-php is
the *trait* use inside a class body — the same node type php.py already
relies on for trait handling. A top-level `use App\Models\User;` is a
`namespace_use_declaration`.
The effect ran in both directions: real imports were dropped entirely, so
PHP files produced no Module nodes and no IMPORTS edges, while trait uses
were recorded as imports. In the repo's own fixture, `use Alpha, Beta {
... }` — a trait conflict-resolution block inside a class — became a
Module named "Alpha" whose full_import_name was the entire block.
Capture `namespace_use_clause` instead. That is the level that exists once
per imported symbol, so the braced group form expands for free, and the
handler now reads the AST rather than regexing the declaration text:
use App\Models\User; -> User (App\Models\User)
use App\Models\Post as BlogPost; -> BlogPost (App\Models\Post)
use Foo\Bar\{A, B as C}; -> A (Foo\Bar\A)
C (Foo\Bar\B)
use function Baz\helper; -> helper (Baz\helper)
`full_import_name` is now the clean fully-qualified path rather than the
raw source text, and rows are sorted by line so output is deterministic.
Golden for sample_project_php regenerated: 5 real imports added, the 2
bogus trait-derived Modules removed.
Co-Authored-By: Claude Fable 5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ |
Contributor
🔍 PR Code Graph Analysisfix(parsers): capture PHP imports instead of trait uses (#1563) 📊 Interactive VisualizationView the blast radius graph: PR Reviewer Dashboard 📦 ArtifactsThe graph JSON has been uploaded as a build artifact: Generated by CodeGraphContext using FalkorDB Lite |
Shashankss1205
added a commit
that referenced
this pull request
Aug 2, 2026
Bug-fix release. Since 0.5.4 on PyPI: - fix(indexer): record non-code files on the SCIP path so `cgc index` stops reporting a partial index forever (#1565, #1566) - fix(parsers): capture PHP imports rather than trait uses (#1522, #1563) - fix(parsers): recover Python annotated parameters — 40.3% of parameters were being dropped — and Go grouped imports (#1520, #1521, #1561) - fix(graph): always sanitize bundle filenames (#1517, #1541) - fix(cli/mcp): read import aliases from the IMPORTS relationship (#1515, #1540) - fix(cli/mcp): fall back to JSON when GCF encoding fails (#1518, #1539) Co-authored-by: Claude Fable 5 <[email protected]>
This branch was successfully deployed
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.
Fixes #1522. Full suite: 1078 passed, 7 skipped, no failures.
The bug
The imports query captured
use_declaration— which in tree-sitter-php is the trait use inside a class body, the same node typephp.pyalready relies on at line ~309 for trait handling. A top-leveluse App\Models\User;is anamespace_use_declaration.This ran in both directions:
Real imports were dropped entirely. PHP files produced no
Modulenodes and noIMPORTSedges, soresolution/calls.pyhad an emptylocal_importsmap for PHP and no call to a class imported from another file could resolve.Trait uses were recorded as imports. The repo's own fixture has a conflict-resolution block inside a class:
That became a
Modulenode namedAlphawhosefull_import_namewas the entire block, newlines and all.The fix
Capture
namespace_use_clauserather than the declaration. That is the level that exists once per imported symbol, so the braced group form expands for free. The handler now reads the AST instead of regexing the declaration text:use App\Models\User;UserApp\Models\Useruse App\Models\Post as BlogPost;BlogPostApp\Models\PostBlogPostuse Foo\Bar\{A, B as C};A,CFoo\Bar\A,Foo\Bar\BCuse function Baz\helper;helperBaz\helperTwo secondary improvements that fell out of it:
full_import_nameis the clean fully-qualified path rather than raw source text (the same defect noted for Rust in bug(indexer): parser audit roundup — context attribution, wrong Module names, missing declarations and duplicate call records across 12 languages #1538).Trait handling is untouched and still works: a
use Greets;inside a class yieldsimports == []withGreetscorrectly intraits.Golden
sample_project_phpregenerated. Verified semantically rather than by line count:New test file
tests/unit/parsers/test_php_parser.pycovers all five import forms, the trait-use case, and ordering.🤖 Generated with Claude Code