* Ensure the appropriate LSP server is started for the given file. * Returns undefined if no server handles this file type. * * @throws {Error} If server fails to start
(
filePath: string,
)
| 215 | * @throws {Error} If server fails to start |
| 216 | */ |
| 217 | async function ensureServerStarted( |
| 218 | filePath: string, |
| 219 | ): Promise<LSPServerInstance | undefined> { |
| 220 | const server = getServerForFile(filePath) |
| 221 | if (!server) return undefined |
| 222 | |
| 223 | if (server.state === 'stopped' || server.state === 'error') { |
| 224 | try { |
| 225 | await server.start() |
| 226 | } catch (error) { |
| 227 | const err = error as Error |
| 228 | logError( |
| 229 | new Error( |
| 230 | `Failed to start LSP server for file ${filePath}: ${err.message}`, |
| 231 | ), |
| 232 | ) |
| 233 | throw error |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return server |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Send a request to the appropriate LSP server for the given file. |
no test coverage detected