Crate codive_lsp

Crate codive_lsp 

Source
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 spawning
  • client: LSP client with JSON-RPC communication
  • facade: High-level API with lazy initialization and caching
  • types: LSP types and utilities
  • language: 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

LanguageServerExtensions
Rustrust-analyzer.rs
TypeScript/JavaScripttypescript-language-server.ts, .tsx, .js, .jsx
Pythonpyright.py, .pyi
Gogopls.go

§LSP Operations

The following LSP operations are supported:

  • goToDefinition - Find where a symbol is defined
  • findReferences - Find all references to a symbol
  • hover - Get hover information (documentation, types)
  • documentSymbol - Get all symbols in a document
  • workspaceSymbol - Search for symbols across the workspace
  • goToImplementation - Find implementations of a trait/interface
  • prepareCallHierarchy - Get call hierarchy item at a position
  • incomingCalls - Find all callers of a function
  • outgoingCalls - 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.
DocumentSymbol
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.
SymbolInformation
Represents information about programming constructs like variables, classes, interfaces etc.
SymbolKind
A symbol kind.
Uri
Newtype struct around fluent_uri::Uri<String> with serialization implementations that use as_str() and ‘from_str()’ respectively.

Enums§

DocumentSymbolResponse
LspError
Error types for LSP operations

Functions§

uri_to_file_path
Convert an LSP Uri to a file path