Skip to content

input: add Lsp::show_document hook following LSP window/showDocument#2569

Merged
ylinwind merged 2 commits into
mainfrom
input-open-location-hook-0.5
Jul 15, 2026
Merged

input: add Lsp::show_document hook following LSP window/showDocument#2569
ylinwind merged 2 commits into
mainfrom
input-open-location-hook-0.5

Conversation

@ylinwind

@ylinwind ylinwind commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What

Adds an optional Lsp::on_show_document host hook on InputState, called at the start of go_to_definition before the built-in handling. The hook is modeled after the LSP window/showDocument request:

pub type ShowDocumentHandler =
    Rc<dyn Fn(&lsp_types::ShowDocumentParams, &mut Window, &mut App) -> bool>;

The component builds ShowDocumentParams from the resolved LocationLink (uri, external for http(s) targets, take_focus, selection from targetSelectionRange).

  • Return true: the host has shown the document; the component does nothing further.
  • Return false (or hook unset): falls through to the existing behavior — external URIs open in the browser, anything else jumps within the current document.

The default in-document jump now selects targetSelectionRange (the range the spec says should be selected and revealed when following a link) instead of targetRange.

Why

The built-in Go to Definition can only jump within the current document or open a browser URL. Language providers that resolve symbols into virtual/external documents (e.g. NaviScript stdlib symbols resolving to navi-doc://module/name) need a way to route Cmd+Click to an in-app docs window. Without a hook, non-http cross-file locations would be misinterpreted as same-document ranges and jump to a wrong position.

window/showDocument is the spec's standard "client, show this document" abstraction, so the hook reuses its params shape rather than inventing a new one.

Notes

  • Branch is based on d1c48828 (the rev currently pinned by longbridge-gpui's Cargo.lock) so it can be consumed immediately; happy to rebase onto main if preferred.
  • go_to_definition (crate-private) gains a &mut Window parameter; both internal call sites already had a window in scope.

🤖 Generated with Claude Code

Hosts can intercept LSP locations before the built-in handling (http(s)
opens in browser, otherwise same-document jump) -- e.g. to open a
virtual navi-doc:// URI in an in-app docs window. Return true to mark
the location handled.
Comment thread crates/ui/src/input/lsp/mod.rs Outdated
@ylinwind ylinwind changed the title input: add Lsp::on_open_location hook to intercept Go to Definition input: add Lsp::on_show_document hook following LSP window/showDocument Jul 14, 2026
Rename on_open_location to on_show_document and pass
lsp_types::ShowDocumentParams (uri, external, take_focus, selection)
instead of a raw LocationLink, following the window/showDocument
request from the LSP spec. The default in-document jump now selects
target_selection_range per the spec, instead of target_range.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ylinwind
ylinwind force-pushed the input-open-location-hook-0.5 branch from 3c1bd60 to e007d25 Compare July 15, 2026 02:23
@ylinwind ylinwind changed the title input: add Lsp::on_show_document hook following LSP window/showDocument input: add Lsp::show_document hook following LSP window/showDocument Jul 15, 2026
@ylinwind
ylinwind merged commit 44877ed into main Jul 15, 2026
3 checks passed
@ylinwind
ylinwind deleted the input-open-location-hook-0.5 branch July 15, 2026 02:52
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