( server: LspServerDefinition, session: string, )
| 256 | * Returns the port number if the server is alive, null otherwise. |
| 257 | */ |
| 258 | export async function canReuseExistingServer( |
| 259 | server: LspServerDefinition, |
| 260 | session: string, |
| 261 | ): Promise<number | null> { |
| 262 | const bridge = server.launcher?.bridge; |
| 263 | const serverName = |
| 264 | resolveServerExecutable(server) || |
| 265 | bridge?.command || |
| 266 | server.launcher?.command || |
| 267 | server.id; |
| 268 | |
| 269 | const portInfo = await getLspPort(serverName, session); |
| 270 | if (!portInfo) { |
| 271 | return null; |
| 272 | } |
| 273 | |
| 274 | const url = `ws://127.0.0.1:${portInfo.port}/`; |
| 275 | const status = await checkAxsBridgeStatus(url, 1000); |
| 276 | const alive = |
| 277 | status === "alive" || |
| 278 | (status === "unsupported" && |
| 279 | (await checkServerAliveViaWebSocket(url, 1000))); |
| 280 | |
| 281 | if (alive) { |
| 282 | addLspLog(server.id, "info", `Reusing existing server on port ${portInfo.port}`); |
| 283 | console.info( |
| 284 | `[LSP:${server.id}] Reusing existing server on port ${portInfo.port}`, |
| 285 | ); |
| 286 | return portInfo.port; |
| 287 | } |
| 288 | |
| 289 | console.info( |
| 290 | `[LSP:${server.id}] Found stale port file, will start new server`, |
| 291 | ); |
| 292 | addLspLog(server.id, "warn", "Found stale port file, starting a new server"); |
| 293 | return null; |
| 294 | } |
| 295 | |
| 296 | function resolveStartCommand( |
| 297 | server: LspServerDefinition, |
no test coverage detected