Skip to content

feat: add Phase 3 definition provider - #242

Merged
j4rviscmd merged 1 commit into
mainfrom
feat/language-host-definition
Jul 25, 2026
Merged

feat: add Phase 3 definition provider#242
j4rviscmd merged 1 commit into
mainfrom
feat/language-host-definition

Conversation

@j4rviscmd

Copy link
Copy Markdown
Owner

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[] } or null
  • Resolve the identifier at the position, 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, declaration predicates, range_from_points); refactored hover/definition into a shared feature_json<T,F> envelope (Rust) and parseJsonObject<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

  1. `cd rust && cargo build`
  2. `npm run watch` + `./scripts/code.sh`
  3. Enable `coderm.languageHost.enabled` and set `coderm.languageHost.languages` (e.g. `["typescript", "tsx"]`)
  4. Open a `.ts` file, place the cursor on a function/variable reference, press `F12` → jumps to the declaration. Multiple same-name declarations → picker.

Verified end-to-end by the user (F12 jump).

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>
@j4rviscmd j4rviscmd added the enhancement New feature or request label Jul 25, 2026
@j4rviscmd
j4rviscmd merged commit 4640965 into main Jul 25, 2026
3 checks passed
@j4rviscmd
j4rviscmd deleted the feat/language-host-definition branch July 25, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant