LSP Capability Detection & Handling
Goto Preview uses a robust strategy to ensure it sends requests to the correct Language Server, especially in environments where multiple LSPs are attached to a single buffer.
Client Selection Strategy
When you trigger a preview (e.g., goto_preview_definition), the plugin follows this logic:
- Capability Check: It iterates through all active clients on the current buffer and checks if they support the specific method (e.g.,
definitionProviderfor definition requests). - Filtering: It creates a list of "capable clients."
- Fallback:
- If capable clients are found, it sends the request only to those clients.
- If no clients advertise the capability explicitly (common with some servers like
jdtls), it falls back to sending the request to all attached clients. - If no clients are attached, it aborts with an error.
Request Handling
The plugin uses vim.lsp.buf_request_all to query the selected clients. It processes the results using the following priority:
- It waits for responses.
- It iterates through the results.
- It picks the first valid result (non-empty) from a client that was in the target list.
- It discards subsequent results to prevent opening multiple windows for the same definition.
Handlers (Legacy vs Modern)
The plugin automatically detects the Neovim version and LSP handler signature:
- Modern (Neovim 0.10+): Expects
(err, result, ctx, config). - Legacy: Expects
(err, method, result).
Note: As of the current version, the plugin explicitly requires Neovim 0.10+.