Skip to content

Type hierarchy over the language server: find_type_hierarchy, and find_implementations falling back to subtypes for a class - #2023

Open
MarioRial22 wants to merge 8 commits into
oraios:mainfrom
rialestate:contrib/type-hierarchy
Open

MarioRial22 wants to merge 8 commits into
oraios:mainfrom
rialestate:contrib/type-hierarchy

Conversation

@MarioRial22

Copy link
Copy Markdown

Closes the issue "find_implementations answers [] for a class" (see the linked issue).

  • SolidLanguageServer.request_type_hierarchy_subtypes / _supertypes: textDocument/prepareTypeHierarchy + typeHierarchy/subtypes|supertypes, each item resolved to the symbol that defines it (the request_implementing_symbols shape). A server that answers MethodNotFound has no type hierarchy: the result is empty, never an error. Types outside the repository (typeshed) are skipped.
  • LanguageServerSymbolRetriever.find_subtype_symbols / find_supertype_symbols, and find_implementing_symbols falling back to the subtypes when the server reports no implementations for a Class or Interface — pyrefly and pyright answer textDocument/implementation for methods only.
  • FindTypeHierarchyTool (find_type_hierarchy, optional): subtypes or supertypes of a class/interface, one level per call, include_info like find_implementations.
  • The Python servers (pyright, basedpyright, ty, pyrefly) and the TypeScript server advertise the textDocument.typeHierarchy client capability.
  • test/conftest.py: project_with_explicit_ls_context, a project that runs the GIVEN language server — project_with_ls_context loads the repo's own project.yml, which for the Python test repo means pyright whatever backend a test asked for.

Tests (test/serena/test_type_hierarchy.py): pyrefly — subtypes of BaseService, supertypes of DataSyncService, the find_implementations fallback; typescript-language-server 5.1.3, which does not implement prepareTypeHierarchy — the empty contract. pyrefly reports the whole chain (indirect descendants and ancestors included), so the assertions are supersets and the docstrings say "as the server reports them".

Checklist

  • This PR follows the guidelines in CONTRIBUTING.md regarding the scope of PRs.
  • For changes that add features or fix problems, I have added an entry to CHANGELOG.md, which concisely describes the change.

…d_implementations falling back to subtypes for a class

textDocument/prepareTypeHierarchy + typeHierarchy/subtypes|supertypes, resolved to the defining symbols; a server without a typeHierarchyProvider (MethodNotFound) answers an empty hierarchy, never an error; types outside the repository (typeshed) are skipped. find_implementations on a class/interface with no implementations reported now returns its subtypes instead of [] (pyright and pyrefly answer textDocument/implementation for methods only). The Python and TypeScript servers advertise the textDocument.typeHierarchy capability. Tests on pyrefly (subtypes, supertypes, the fallback) and on typescript-language-server 5.1.3, which has no type hierarchy (the empty contract).
… with Path.is_relative_to

On GitHub's Windows runner the repository lives on D: and pyrefly's typeshed
on C:, and os.path.commonpath raises ValueError for paths on different drives
instead of answering. The supertypes of a class inheriting from ABC then
failed on Windows instead of skipping the typeshed item, which is what the
check is there to do. Path.is_relative_to answers False across drives, and it
is the idiom the rest of the module already uses.
@CLAassistant

CLAassistant commented Sep 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

… the LSP facade

Upstream reified the tool layer while this branch was open: an LspApi
facade now holds the logic, tools delegate to it through LspApiMixin, and
each facade method names its corresponding tool. FindTypeHierarchyTool
was written before that existed, so the merge adapts it rather than
keeping a tool that reaches for the symbol retriever directly:

- LspApi.find_type_hierarchy, mirroring find_implementations (the closest
  sibling: same LspSymbolCollection, same include_info handling), marked
  optional and carrying corresponding_tool=FindTypeHierarchyTool.
- FindTypeHierarchyTool keeps its signature and docstring and delegates
  to that method, like FindReferencingSymbolsTool and the rest.

The retriever methods this stands on (find_subtype_symbols /
find_supertype_symbols and the find_implementations fallback in
symbol.py) merged unchanged.
@opcode81 opcode81 added the internal discussion This issue/PR should is flagged for discussion among maintainers. label Oct 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal discussion This issue/PR should is flagged for discussion among maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants