coderlib/lsp/
mod.rs

1//! Language Server Protocol (LSP) integration for CoderLib
2//!
3//! This module provides LSP client functionality to enable code intelligence
4//! features like diagnostics, hover information, and completions.
5
6pub mod client;
7pub mod manager;
8pub mod config;
9pub mod types;
10
11pub use client::LspClient;
12pub use manager::LspManager;
13pub use config::{LspConfig, LspServerConfig};
14pub use types::{
15    LspError, LspDiagnostic, DiagnosticSeverity, Position, Range, Location,
16    CompletionItem, CompletionItemKind, Hover, CodeAction, SymbolInformation, SymbolKind
17};
18
19use std::path::Path;
20use async_trait::async_trait;
21
22/// Main trait for LSP functionality
23#[async_trait]
24pub trait LspService: Send + Sync {
25    /// Get diagnostics for a file
26    async fn get_diagnostics(&self, file_path: &Path) -> Result<Vec<LspDiagnostic>, LspError>;
27
28    /// Notify LSP of file changes
29    async fn did_change_file(&self, file_path: &Path, content: &str) -> Result<(), LspError>;
30
31    /// Notify LSP of file open
32    async fn did_open_file(&self, file_path: &Path, content: &str) -> Result<(), LspError>;
33
34    /// Notify LSP of file close
35    async fn did_close_file(&self, file_path: &Path) -> Result<(), LspError>;
36
37    /// Check if LSP is available for a file type
38    fn supports_file(&self, file_path: &Path) -> bool;
39
40    /// Get code completions at a position
41    async fn get_completions(&self, file_path: &Path, position: Position) -> Result<Vec<CompletionItem>, LspError>;
42
43    /// Go to definition of symbol at position
44    async fn goto_definition(&self, file_path: &Path, position: Position) -> Result<Vec<Location>, LspError>;
45
46    /// Get hover information at position
47    async fn get_hover(&self, file_path: &Path, position: Position) -> Result<Option<Hover>, LspError>;
48
49    /// Find references to symbol at position
50    async fn find_references(&self, file_path: &Path, position: Position, include_declaration: bool) -> Result<Vec<Location>, LspError>;
51
52    /// Get code actions for a range
53    async fn get_code_actions(&self, file_path: &Path, range: Range) -> Result<Vec<CodeAction>, LspError>;
54
55    /// Get document symbols
56    async fn get_document_symbols(&self, file_path: &Path) -> Result<Vec<SymbolInformation>, LspError>;
57
58    /// Format document
59    async fn format_document(&self, file_path: &Path) -> Result<String, LspError>;
60
61    /// Format range in document
62    async fn format_range(&self, file_path: &Path, range: Range) -> Result<String, LspError>;
63}