pub struct LspClient { /* private fields */ }Expand description
LSP Client
Manages a single LSP server connection and provides high-level API for common LSP operations like hover, definition, references, and diagnostics.
Implementations§
Source§impl LspClient
impl LspClient
Sourcepub fn new(
language: impl Into<String>,
server_name: impl Into<String>,
project_root: PathBuf,
) -> Self
pub fn new( language: impl Into<String>, server_name: impl Into<String>, project_root: PathBuf, ) -> Self
Create a new LSP client
Sourcepub fn from_config(config: &LspServerConfig, project_root: PathBuf) -> Self
pub fn from_config(config: &LspServerConfig, project_root: PathBuf) -> Self
Create LSP client from config
Sourcepub async fn spawn(&self, config: &LspServerConfig) -> Result<()>
pub async fn spawn(&self, config: &LspServerConfig) -> Result<()>
Spawn and initialize the LSP server
Sourcepub async fn spawn_async(
&self,
config: &LspServerConfig,
progress_callback: Arc<dyn LspProgressCallback>,
) -> Result<()>
pub async fn spawn_async( &self, config: &LspServerConfig, progress_callback: Arc<dyn LspProgressCallback>, ) -> Result<()>
Spawn LSP server with async initialization and progress callbacks
This is the async version of spawn() with:
- Separate timeouts for process startup (5s) and server initialization (60s)
- Progress callbacks for UI updates
- Better error messages for each phase
§Arguments
config: LSP server configurationprogress_callback: Callback for progress updates (can beNoOpProgressCallbackif not needed)
§Progress Flow
- 0.1: Starting process…
- 0.3: Process started, initializing server…
- 0.5-0.9: Loading workspace/indexes…
- 1.0: Ready
§Errors
- Process startup timeout (5s): binary missing, permission denied
- Server initialization timeout (60s): large workspace, slow indexing
Sourcepub async fn initialize(&self) -> Result<()>
pub async fn initialize(&self) -> Result<()>
Send LSP initialize request
Sourcepub async fn initialized(&self) -> Result<()>
pub async fn initialized(&self) -> Result<()>
Send initialized notification
Sourcepub async fn open_file(&self, uri: &Url, content: &str) -> Result<()>
pub async fn open_file(&self, uri: &Url, content: &str) -> Result<()>
Open a file in the LSP server
Sourcepub async fn hover(
&self,
uri: &Url,
position: Position,
) -> Result<Option<HoverResult>>
pub async fn hover( &self, uri: &Url, position: Position, ) -> Result<Option<HoverResult>>
Get hover information at a position
Sourcepub async fn definition(
&self,
uri: &Url,
position: Position,
) -> Result<Vec<Location>>
pub async fn definition( &self, uri: &Url, position: Position, ) -> Result<Vec<Location>>
Get definition locations at a position
Sourcepub async fn references(
&self,
uri: &Url,
position: Position,
include_declaration: bool,
) -> Result<Vec<Location>>
pub async fn references( &self, uri: &Url, position: Position, include_declaration: bool, ) -> Result<Vec<Location>>
Get reference locations at a position
Sourcepub async fn diagnostics(&self, uri: &Url) -> Result<Vec<Diagnostic>>
pub async fn diagnostics(&self, uri: &Url) -> Result<Vec<Diagnostic>>
Get diagnostics for a file from cache
Sourcepub async fn update_diagnostics(&self, uri: Url, diagnostics: Vec<Diagnostic>)
pub async fn update_diagnostics(&self, uri: Url, diagnostics: Vec<Diagnostic>)
Update diagnostics cache (called when receiving publishDiagnostics notification)
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if the client is connected
Sourcepub fn server_name(&self) -> &str
pub fn server_name(&self) -> &str
Get the server name
Sourcepub fn project_root(&self) -> &PathBuf
pub fn project_root(&self) -> &PathBuf
Get the project root
Sourcepub async fn capabilities(&self) -> Option<ServerCapabilities>
pub async fn capabilities(&self) -> Option<ServerCapabilities>
Get server capabilities