Expand description
LSP client infrastructure for the AI coding agent
This crate provides Language Server Protocol (LSP) integration, enabling the agent to leverage code intelligence from language servers like rust-analyzer, typescript-language-server, pyright, and gopls.
§Architecture
The crate is organized into several modules:
server: LSP server definitions and spawningclient: LSP client with JSON-RPC communicationfacade: High-level API with lazy initialization and cachingtypes: LSP types and utilitieslanguage: File extension to language ID mappings
§Usage
ⓘ
use codive_lsp::facade::{init, lsp};
use std::path::PathBuf;
// Initialize the LSP subsystem
let working_dir = PathBuf::from("/path/to/project");
init(working_dir);
// Get the LSP instance
let lsp = lsp().unwrap();
// Touch a file to notify LSP servers
lsp.touch_file(Path::new("src/main.rs"), true).await?;
// Go to definition
let locations = lsp.definition(Path::new("src/main.rs"), 10, 5).await?;§Supported Language Servers
| Language | Server | Extensions |
|---|---|---|
| Rust | rust-analyzer | .rs |
| TypeScript/JavaScript | typescript-language-server | .ts, .tsx, .js, .jsx |
| Python | pyright | .py, .pyi |
| Go | gopls | .go |
§LSP Operations
The following LSP operations are supported:
goToDefinition- Find where a symbol is definedfindReferences- Find all references to a symbolhover- Get hover information (documentation, types)documentSymbol- Get all symbols in a documentworkspaceSymbol- Search for symbols across the workspacegoToImplementation- Find implementations of a trait/interfaceprepareCallHierarchy- Get call hierarchy item at a positionincomingCalls- Find all callers of a functionoutgoingCalls- Find all functions called by a function
Re-exports§
pub use client::LspClient;pub use facade::init;pub use facade::lsp;pub use facade::Lsp;pub use server::LspRegistry;pub use server::LspServerHandle;pub use server::LspServerInfo;pub use types::format_diagnostic;pub use types::LspConnectionStatus;pub use types::LspOperation;pub use types::LspResult;pub use types::LspStatus;
Modules§
- client
- LSP client implementation
- facade
- LSP facade providing high-level API
- language
- File extension to language ID mappings
- server
- LSP server definitions and spawning
- types
- LSP types and re-exports
Structs§
- Diagnostic
- Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a resource.
- Document
Symbol - Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range, e.g. the range of an identifier.
- Hover
- The result of a hover request.
- Location
- Represents a location inside a resource, such as a line inside a text file.
- Position
- Position in a text document expressed as zero-based line and character offset. A position is between two characters like an ‘insert’ cursor in a editor.
- Range
- A range in a text document expressed as (zero-based) start and end positions. A range is comparable to a selection in an editor. Therefore the end position is exclusive.
- Symbol
Information - Represents information about programming constructs like variables, classes, interfaces etc.
- Symbol
Kind - A symbol kind.
- Uri
- Newtype struct around
fluent_uri::Uri<String>with serialization implementations that useas_str()and ‘from_str()’ respectively.
Enums§
- Document
Symbol Response - LspError
- Error types for LSP operations
Functions§
- uri_
to_ file_ path - Convert an LSP Uri to a file path