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 theaxon-lspBackend can deserialise anaxon/askAdvisorrequest and reply with a structuredMethodNotFoundeven when the advisor itself is absent. -
Feature-gated surface (
#[cfg(feature = "llm")]). With--features llmthe [Advisor] struct is exposed, plus atry_advisor_from_envhelper. The advisor depends onreqwestand the embeddedlsp-docscorpus; 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}.mdfor 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. - Code
Context - 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
claudeis 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.