Skip to content

Fix PHP symbol retrieval: declare missing Intelephense client capabilities#1099

Open
EarthmanWeb wants to merge 3 commits intooraios:mainfrom
EarthmanWeb:fix/php-symbol-retrieval
Open

Fix PHP symbol retrieval: declare missing Intelephense client capabilities#1099
EarthmanWeb wants to merge 3 commits intooraios:mainfrom
EarthmanWeb:fix/php-symbol-retrieval

Conversation

@EarthmanWeb
Copy link
Contributor

Problem

Intelephense's LSP server conditionally enables certain features based
on what the client declares it supports in the initialize request.
Serena's Intelephense client was missing several capability declarations:

  • textDocument.documentSymbol (with hierarchicalDocumentSymbolSupport)
  • textDocument.references
  • textDocument.hover
  • workspace.symbol

Without hierarchicalDocumentSymbolSupport: true, Intelephense falls
back to returning flat SymbolInformation[] instead of the nested
DocumentSymbol[] tree. This means symbol retrieval works partially
or not at all — classes and their methods appear as disconnected
root-level symbols with no parent-child relationship.

Additionally, when find_symbol is called with a specific PHP file
path, it iterated all language servers rather than routing to the
correct one, causing PHP files to be rejected by non-PHP servers.

Fix

  • intelephense.py: Added missing client capability declarations
    for documentSymbol (with full hierarchicalDocumentSymbolSupport
    and symbolKind range), references, hover, and workspace
    symbol. Also added assertion that the server confirms
    documentSymbolProvider support after initialization.

  • symbol.py: When find_symbols is called with a specific file
    path, route to the appropriate language server via
    get_language_server() instead of iterating all servers.

Example

Before:

# Intelephense returned flat SymbolInformation[] — no hierarchy
symbols = get_symbols_overview("src/Controller.php")
# → {"MyController": [], "index": [], "show": []}
# (methods appear at root level, not nested under class)

After:

symbols = get_symbols_overview("src/Controller.php")
# → {"MyController": {"index": {}, "show": {}}}
# (proper hierarchy via DocumentSymbol[])

docs/sample.php Outdated
@@ -0,0 +1,665 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it shall provide the basis for tests (which it probably should), please move this the PHP test repository.
If it shall not provide the basis for tests, delete it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed and provided a new sample file and test

Copy link
Contributor

@opcode81 opcode81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should be added which validate that the changes result in the improvements described.
In particular, we should explicitly inspect the hierarchical structure in tests.

Two related fixes:

1. intelephense.py: Add missing client capability declarations for
   documentSymbol (with hierarchical support), references, hover, and
   workspace symbol. Without these, Intelephense does not advertise
   documentSymbolProvider and returns empty results for get_symbols_overview.

2. symbol.py (LanguageServerSymbolRetriever.find_symbols): When searching
   within a specific file, route to the file-type-appropriate language server
   via get_language_server() instead of querying all servers. This ensures
   PHP files are served by Intelephense and not silently skipped.

Add generic PHP sample to test repository for use as test basis.
@EarthmanWeb EarthmanWeb force-pushed the fix/php-symbol-retrieval branch from 9fee2ac to 0472f4d Compare March 5, 2026 13:48
- test_document_symbols_hierarchical_structure: verifies Intelephense
  returns DocumentSymbol[] with class/method hierarchy (not flat
  SymbolInformation[]) when hierarchicalDocumentSymbolSupport is declared

- test_full_symbol_tree_within_file: verifies request_full_symbol_tree
  scoped to sample.php returns Dog/Animal/greet/fetch with Dog containing
  greet as a child (not at root level)

- test_find_symbol_within_php_file: verifies find_symbol with a PHP
  file path (relative_path=) routes to the PHP language server via
  get_language_server() rather than iterating all servers
@EarthmanWeb
Copy link
Contributor Author

Tests should be added which validate that the changes result in the improvements described. In particular, we should explicitly inspect the hierarchical structure in tests.

All 19 PHP tests pass. Summary of what was added:

test/solidlsp/php/test_php_basic.py — 2 new tests:

test_document_symbols_hierarchical_structure — directly validates the hierarchicalDocumentSymbolSupport fix: asserts Dog class has greet, fetch, getBreed, describe as children (not disconnected root-level symbols), and that those methods do NOT appear at root level
test_full_symbol_tree_within_file — validates request_full_symbol_tree(within_relative_path="sample.php") returns the correct class/method hierarchy
test/serena/test_serena_agent.py — 1 new test:

test_find_symbol_within_php_file — validates the symbol.py routing fix: calls find_symbol(name_path_pattern="Dog/greet", relative_path="sample.php") and asserts the symbol is found (would return empty before the fix, as non-PHP servers would reject the file)

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.

2 participants