MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / canReuseExistingServer

Function canReuseExistingServer

src/cm/lsp/serverLauncher.ts:258–294  ·  view source on GitHub ↗
(
  server: LspServerDefinition,
  session: string,
)

Source from the content-addressed store, hash-verified

256 * Returns the port number if the server is alive, null otherwise.
257 */
258export 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
296function resolveStartCommand(
297 server: LspServerDefinition,

Callers 1

ensureServerRunningFunction · 0.85

Calls 5

checkAxsBridgeStatusFunction · 0.90
addLspLogFunction · 0.90
resolveServerExecutableFunction · 0.85
getLspPortFunction · 0.85

Tested by

no test coverage detected