Skip to content

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

Open
EarthmanWeb wants to merge 1 commit intooraios:mainfrom
EarthmanWeb:fix/php-symbol-retrieval
Open

Fix PHP symbol retrieval: declare missing Intelephense client capabilities#1099
EarthmanWeb wants to merge 1 commit 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[])

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.
@@ -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

@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.

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