Starts an LSP server. workspace_root: Workspace root path, provided by the caller (WorkspaceLspManager). crash_callback: Callback invoked when the process crashes. progress_callback: Indexing progress callback. token_create_callback: Token creation callback. diagnostics_callback: Diagnostics callback.
(
&self,
language: &str,
workspace_root: Option<PathBuf>,
crash_callback: Option<CrashCallback>,
progress_callback: Option<ProgressCallback>,
token_crea
| 121 | /// token_create_callback: Token creation callback. |
| 122 | /// diagnostics_callback: Diagnostics callback. |
| 123 | pub async fn start_server( |
| 124 | &self, |
| 125 | language: &str, |
| 126 | workspace_root: Option<PathBuf>, |
| 127 | crash_callback: Option<CrashCallback>, |
| 128 | progress_callback: Option<ProgressCallback>, |
| 129 | token_create_callback: Option<TokenCreateCallback>, |
| 130 | diagnostics_callback: Option<DiagnosticsCallback>, |
| 131 | ) -> Result<()> { |
| 132 | let plugin = { |
| 133 | let registry = self.registry.read().await; |
| 134 | match registry.find_by_language(language).cloned() { |
| 135 | Some(plugin) => plugin, |
| 136 | None => { |
| 137 | let err = anyhow!("No LSP plugin found for language: {}", language); |
| 138 | warn!("{} (this is expected for plaintext)", err); |
| 139 | return Err(err); |
| 140 | } |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | let plugin_id = plugin.id.clone(); |
| 145 | |
| 146 | { |
| 147 | let processes = self.processes.read().await; |
| 148 | if processes.contains_key(language) { |
| 149 | return Ok(()); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | let server_path = self.plugin_loader.get_server_path(&plugin).map_err(|e| { |
| 154 | error!("Failed to get server path: {}", e); |
| 155 | e |
| 156 | })?; |
| 157 | |
| 158 | let process = LspServerProcess::spawn( |
| 159 | plugin_id.clone(), |
| 160 | server_path.clone(), |
| 161 | &plugin.server, |
| 162 | crash_callback, |
| 163 | progress_callback, |
| 164 | token_create_callback, |
| 165 | diagnostics_callback, |
| 166 | ) |
| 167 | .await |
| 168 | .map_err(|e| { |
| 169 | error!("Failed to spawn process: {}", e); |
| 170 | e |
| 171 | })?; |
| 172 | |
| 173 | let root_uri = workspace_root.and_then(|p| p.to_str().map(|s| s.to_string())); |
| 174 | |
| 175 | process.initialize(root_uri.clone()).await.map_err(|e| { |
| 176 | error!("Failed to initialize LSP connection: {}", e); |
| 177 | e |
| 178 | })?; |
| 179 | |
| 180 | { |
no test coverage detected