ricecoder_external_lsp/lib.rs
1//! External Language Server Protocol (LSP) integration for RiceCoder
2//!
3//! This crate provides integration with external LSP servers to provide real semantic
4//! intelligence for code completion, diagnostics, hover, and navigation across multiple
5//! programming languages.
6//!
7//! # Features
8//!
9//! - **Configuration-Driven**: Support unlimited LSP servers through YAML configuration
10//! - **Process Management**: Automatic spawning, monitoring, and restart of LSP servers
11//! - **Output Mapping**: Transform LSP server responses to ricecoder models via configuration
12//! - **Graceful Degradation**: Fall back to internal providers when external LSP unavailable
13//! - **Multi-Language Support**: Pre-configured for Rust, TypeScript, Python, Go, Java, and more
14//!
15//! # Architecture
16//!
17//! The external LSP integration follows a layered architecture:
18//!
19//! ```text
20//! ┌─────────────────────────────────────────────────────────────────────────┐
21//! │ Ricecoder LSP Proxy │
22//! ├─────────────────────────────────────────────────────────────────────────┤
23//! │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────────┐ │
24//! │ │ LSP Server │ │ Request │ │ Response │ │
25//! │ │ Registry │ │ Router │ │ Merger │ │
26//! │ │ (Config) │ │ (Language) │ │ (External + Internal) │ │
27//! │ └────────┬────────┘ └────────┬────────┘ └────────────┬────────────┘ │
28//! │ │ │ │ │
29//! │ ┌────────▼────────────────────▼────────────────────────▼────────────┐ │
30//! │ │ External LSP Client Pool │ │
31//! │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
32//! │ │ │ rust-analyzer│ │ tsserver │ │ pylsp │ ... │ │
33//! │ │ │ Client │ │ Client │ │ Client │ │ │
34//! │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │
35//! │ └───────────────────────────────────────────────────────────────────┘ │
36//! │ │
37//! │ ┌─────────────────────────────────────────────────────────────────┐ │
38//! │ │ Process Manager │ │
39//! │ │ - Spawn/terminate LSP server processes │ │
40//! │ │ - Health monitoring and auto-restart │ │
41//! │ │ - Resource management (memory, CPU limits) │ │
42//! │ └─────────────────────────────────────────────────────────────────┘ │
43//! │ │
44//! │ ┌─────────────────────────────────────────────────────────────────┐ │
45//! │ │ Fallback Provider │ │
46//! │ │ - Internal completion (existing ricecoder-completion) │ │
47//! │ │ - Internal diagnostics (existing ricecoder-lsp) │ │
48//! │ │ - Used when external LSP unavailable │ │
49//! │ └─────────────────────────────────────────────────────────────────┘ │
50//! └─────────────────────────────────────────────────────────────────────────┘
51//! ```
52//!
53//! # Module Organization
54//!
55//! - `registry`: LSP server registry and configuration management
56//! - `client`: LSP client communication and protocol handling
57//! - `process`: LSP server process management
58//! - `mapping`: Output mapping and transformation
59//! - `merger`: Response merging from multiple sources
60//! - `error`: Error types and result types
61//! - `types`: Core data structures
62
63pub mod client;
64pub mod error;
65pub mod mapping;
66pub mod merger;
67pub mod process;
68pub mod registry;
69pub mod semantic;
70pub mod storage_integration;
71pub mod types;
72
73// Re-export public API
74pub use client::{
75 CapabilityNegotiator, ClientCapabilities, JsonRpcError, JsonRpcHandler, JsonRpcMessage,
76 JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, LspConnection, PendingRequest, RequestId,
77 ServerCapabilities,
78};
79pub use error::{ExternalLspError, Result};
80pub use mapping::{CompletionMapper, DiagnosticsMapper, HoverMapper, JsonPathParser, OutputTransformer};
81pub use merger::{CompletionMerger, DiagnosticsMerger, HoverMerger};
82pub use process::{ClientPool, HealthChecker, ProcessManager};
83pub use registry::{ConfigLoader, DefaultServerConfigs, ServerDiscovery};
84pub use semantic::SemanticFeatures;
85pub use storage_integration::StorageConfigLoader;
86pub use types::{
87 ClientState, CompletionMappingRules, DiagnosticsMappingRules, ExternalLspResult, GlobalLspSettings,
88 HealthStatus, HoverMappingRules, LspServerConfig, LspServerRegistry, MergeConfig, OutputMappingConfig,
89 ResultSource,
90};