feat: add Phase 3 definition provider - #242
Merged
Merged
Conversation
Phase 3 — tree-sitter-backed DefinitionProvider (Go to Definition): Message::Definition { uri, line, column } -> DefinitionResponse { locations: Location[] } or null. Resolve the identifier at the position (named_descendant + is_definition_trigger_kind), then recursively walk the document AST collecting declarations whose name token matches; return all matches as Location[] (file-local only). All matches so VS Code shows a picker on ambiguous/overloaded/shadowed names.
Reuses Phase 2 helpers (UTF-16->UTF-8 column reconciliation, declaration predicates, range_from_points). Refactored hover/definition into a shared feature_json<T,F> envelope in Rust and parseJsonObject<T> in the renderer to keep the two *_json / parse* pairs DRY.
Known limitation (documented): file-local, name-based resolution — no cross-file type resolution like tsserver, no scope-aware shadowing/overload filtering. Coexists with the built-in TS provider (non-exclusive, Phase 1 pattern).
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 3 of the native (Rust) Language Host: tree-sitter-backed DefinitionProvider (Go to Definition), continuing Phase 0→1→2 (documentSymbol/foldingRange/hover already merged).
Phase 3 — Definition
Message::Definition { uri, line, column }→DefinitionResponse { locations: Location[] }ornullnametoken matches; return all matches asLocation[](file-local only)range_from_points); refactored hover/definition into a sharedfeature_json<T,F>envelope (Rust) andparseJsonObject<T>(renderer)Known limitation
File-local, name-based resolution — no cross-file type resolution like tsserver, no scope-aware shadowing/overload filtering. The provider is non-exclusive and coexists with the built-in TS extension (Phase 1 pattern), so simple buffer-local jumps are offloaded while tsserver handles complex cases.
How to verify
Verified end-to-end by the user (F12 jump).