Skip to main content

Crate lsp_llm

Crate lsp_llm 

Source
Expand description

lsp-llm — opt-in LLM advisor.

The crate has two faces:

  • Always-on surface (AskRequest, AskResponse, Citation, is_compiled_in, is_runtime_enabled, is_active). These types ship in every build so the axon-lsp Backend can deserialise an axon/askAdvisor request and reply with a structured MethodNotFound even when the advisor itself is absent.

  • Feature-gated surface (#[cfg(feature = "llm")]). With --features llm the [Advisor] struct is exposed, plus a try_advisor_from_env helper. The advisor depends on reqwest and the embedded lsp-docs corpus; both stay out of the dep tree on default builds.

Activation requires both axes to be true:

  • Compile-time: --features llm (lights up [Advisor]).
  • Runtime: AXON_LSP_LLM_ENABLED=1 (the Backend opts in).

If either is missing, axon/askAdvisor returns MethodNotFound with an explanatory message. Diagnostics, hover, completion, and definition keep working at full fidelity — the deterministic stack never depends on this crate at runtime.

Structs§

AskRequest
JSON-RPC request payload for axon/askAdvisor.
AskResponse
JSON-RPC response payload for axon/askAdvisor.
Citation
One citation accompanying an answer. Today the URI is a synthetic axon-lsp://docs/{kind}/{name}.md for documentation entries, or the source URI when the advisor cited the user’s own code. Editors may not be able to navigate the synthetic scheme, but the data is structured for future routing.
CodeContext
Optional code context the client can attach to a request.

Constants§

ENV_ANTHROPIC_KEY
Environment variable carrying the Anthropic API key when AXON_LLM_BACKEND=claude.
ENV_BACKEND
Environment variable that selects the backend. Today only claude is wired; the slot exists so future backends can plug in without a schema change.
ENV_ENABLED
Environment variable that flips the runtime opt-in.
ENV_MODEL
Environment variable that overrides the default Anthropic model.
METHOD
Custom LSP method name. Both the server and any LSP client that wants to call the advisor must agree on this string.

Functions§

is_active
Whether the advisor is fully active — both compile-time and runtime gates must say yes. The Backend uses this to decide between routing through the advisor and replying with MethodNotFound.
is_compiled_in
True when the binary was compiled with --features llm.
is_runtime_enabled
True when the runtime opt-in env var is set to 1. Reads the process environment on every call — the advisor is rare enough (one call per user question) that caching adds no value.