Skip to content

bug(indexer): PHP imports query matches use_declaration (trait use) instead of namespace_use_declaration, so PHP files produce no imports at all #1522

Closed

Description

@Shashankss1205

tools/languages/php.py:35

The imports query captures (use_declaration). That is the trait use inside a class body — php.py relies on exactly that at line 309. A top-level use App\Models\User; is a different node type: namespace_use_declaration.

Reproduction

$ .venv/bin/python -c "
from codegraphcontext.tools.tree_sitter_parser import TreeSitterParser
from codegraphcontext.tools.languages.php import PhpTreeSitterParser
import tempfile, pathlib
p = pathlib.Path(tempfile.mkdtemp())/'a.php'
p.write_text('<?php\nuse App\\\\Models\\\\User;\nuse App\\\\Models\\\\Post as BlogPost;\n')
print([i.get('name') for i in PhpTreeSitterParser(TreeSitterParser('php')).parse(str(p))['imports']])
"
[]

Two consequences, in opposite directions:

  • Real imports are dropped entirely — PHP files produce no Module nodes and no IMPORTS edges.
  • Trait uses inside class bodies are captured by this query, so they are mislabelled as imports. Across the PHP fixtures the only two "imports" found are trait uses; all four genuine imports are missing.

Impact

use is how PHP does every cross-file reference. With no import data, resolution/calls.py has an empty local_imports map for PHP, so no call to a class imported from another file can be resolved to its definition. PHP call graphs are limited to same-file resolution.

Suggested fix

Capture namespace_use_declaration for imports and keep use_declaration for the trait-use handling that already exists at line 309 — they are genuinely different constructs and should not share a query.


Environment
Commit c0e0bed (main)
Python 3.12.3, Linux

Reproduced with the snippet above and against the repo's PHP fixtures.

Activity

  1. added
    bugSomething isn't working
    severity: highWrong graph content, data loss, or a broken workflow with no clear signal
    area: indexerParsing, discovery, resolution, persistence
    on Aug 1, 2026
  2. github-actions commented on Aug 1, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  3. moved this from Backlog tasks to In progress in CGC Progress Boardon Aug 2, 2026
  4. moved this from In progress to Done in CGC Progress Boardon Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: indexerParsing, discovery, resolution, persistencebugSomething isn't workingseverity: highWrong graph content, data loss, or a broken workflow with no clear signal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions