Skip to content

Fix PHP find_symbol: handle flat SymbolInformation#1097

Open
EarthmanWeb wants to merge 7 commits into
oraios:mainfrom
EarthmanWeb:fix/php-symbol-routing
Open

Fix PHP find_symbol: handle flat SymbolInformation#1097
EarthmanWeb wants to merge 7 commits into
oraios:mainfrom
EarthmanWeb:fix/php-symbol-routing

Conversation

@EarthmanWeb

Copy link
Copy Markdown
Contributor

Problem

Two related issues cause find_symbol to fail or return wrong results in PHP projects:

1. Incorrect language server routing
In multi-language projects, get_language_server() routed files using
is_ignored_path() — a method that checks gitignore and unsupported
extension filters. A PHP file could pass or fail this check for the
wrong language server depending on configuration order, causing PHP
files to be routed to the Python LS (or vice versa).

2. Flat SymbolInformation[] from Intelephense
For some PHP files, Intelephense returns SymbolInformation[] (the
older LSP format) instead of DocumentSymbol[]. These symbols have no
parent-child hierarchy — methods appear as root-level symbols with only
a containerName string field linking them to their class.

find_symbol("ClassName/method") failed silently because
iter_name_path_components_reversed() never yielded the container,
so the name-path match never succeeded.

3. Hard error on explicitly-requested ignored file
When get_symbols_overview() was called on a file that happened to
match an ignore pattern, it raised a hard error and returned []
instead of proceeding. This broke workflows where the caller explicitly
requested a specific file.

Fix

  • ls_manager.py: Route by fn_matcher.is_relevant_filename()
    checks the file extension against the language's known extensions —
    instead of is_ignored_path().

  • symbol.py: Added containerName fallback in
    iter_name_path_components_reversed(). When a symbol has no
    ancestors (flat SymbolInformation), yield the containerName value
    so name-path patterns like "ClassName/method" still match.

  • ls.py: Downgraded hard error to a warning when an explicitly
    requested file is ignored; proceed with the symbol request anyway.

Example

Before:

# In a Python+PHP project:
find_symbol("TestWebhookHandler/handle_request")
# → [] (routed to wrong LS, or containerName not traversed)

After:

find_symbol("TestWebhookHandler/handle_request")
# → [<LanguageServerSymbol: handle_request>]

Comment thread src/serena/symbol.py Outdated
Comment thread src/serena/ls_manager.py Outdated
@MischaPanch

Copy link
Copy Markdown
Member

@opcode81 @EarthmanWeb what's the status here?

@opcode81
opcode81 force-pushed the main branch 4 times, most recently from fee8b1c to d165272 Compare April 6, 2026 21:08
…mation

Three related fixes for PHP symbol resolution:

1. ls_manager.get_language_server(): route to language server by file
   extension (via get_source_fn_matcher) instead of is_ignored_path, so
   PHP files are correctly dispatched to Intelephense.

2. ls.get_symbols_overview(): when a file is explicitly requested but
   matches an ignore pattern, warn and proceed instead of returning an
   empty list.

3. symbol.iter_name_path_components_reversed(): add containerName fallback
   for flat SymbolInformation responses (Intelephense returns these for some
   PHP files), enabling name-path patterns like "ClassName/method" to match.
Intelephense can return flat SymbolInformation[] (no parent-child links)
instead of DocumentSymbol[] for some PHP files. The previous fix placed a
containerName fallback inside LanguageServerSymbol.iter_name_path_components_reversed,
polluting the generic symbol layer with a language-server-specific quirk.

Moved the fix to the correct layer per reviewer feedback:

- intelephense.py: Override _request_document_symbols to detect flat
  SymbolInformation[] (identified by a top-level "location" key) and
  reconstruct a proper DocumentSymbol[] tree using containerName to wire
  up parent-child relationships before the result reaches shared code.

- symbol.py: Revert iter_name_path_components_reversed to its original
  clean form; no Intelephense-specific knowledge belongs here.

- test_symbol.py: Remove TestLanguageServerSymbolFlatContainerName, which
  tested the now-removed containerName fallback in the generic class.

- test_php_basic.py: Add TestIntelephenseReconstructDocumentSymbols with
  four unit tests covering _reconstruct_document_symbols directly (root
  symbols, method-to-class attachment, orphan handling, two-class
  separation). The existing integration test test_find_symbol_class_method
  continues to cover the end-to-end path through Intelephense.
The _request_document_symbols override now reconstructs flat
SymbolInformation[] into DocumentSymbol[], changing the cached
data format. Bump version to invalidate stale cache entries.
@EarthmanWeb
EarthmanWeb force-pushed the fix/php-symbol-routing branch from 024d71e to 8e9402e Compare May 7, 2026 09:38
@EarthmanWeb

Copy link
Copy Markdown
Contributor Author

Rebased on current main and added the cache invalidation fix.

cache_version_raw_document_symbols is now set to 2 in Intelephense's super().init call, since _request_document_symbols now reconstructs flat SymbolInformation[] into DocumentSymbol[], changing the cached data format.

The get_language_server routing change was dropped — upstream's _get_suitable_language_server already handles extension-based routing correctly.

@MischaPanch
MischaPanch force-pushed the main branch 2 times, most recently from 420a0ba to 016ccbe Compare May 26, 2026 11:45
@MischaPanch
MischaPanch force-pushed the main branch 6 times, most recently from ee32c5e to ebe7646 Compare June 28, 2026 20:38
@opcode81
opcode81 force-pushed the fix/php-symbol-routing branch from edb6fd7 to 93bdb5b Compare July 17, 2026 16:05
Conflicts:
	src/solidlsp/language_servers/intelephense.py
	src/solidlsp/ls.py
@opcode81
opcode81 force-pushed the fix/php-symbol-routing branch from 93bdb5b to d324e6d Compare July 17, 2026 16:07
@opcode81 opcode81 changed the title Fix PHP find_symbol: route by file extension, handle flat SymbolInformation Fix PHP find_symbol: handle flat SymbolInformation Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants