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

Function readPortFromFile

src/cm/lsp/serverLauncher.ts:142–167  ·  view source on GitHub ↗

* Read the port from a port file using the filesystem API. * Returns null if the file doesn't exist or contains invalid data.

(filePath: string)

Source from the content-addressed store, hash-verified

140 * Returns null if the file doesn't exist or contains invalid data.
141 */
142async function readPortFromFile(filePath: string): Promise<number | null> {
143 try {
144 // Dynamic import to get fsOperation
145 const { default: fsOperation } = await import("fileSystem");
146 const fs = fsOperation(filePath);
147
148 // Check if file exists first
149 const exists = await fs.exists();
150 if (!exists) {
151 return null;
152 }
153
154 // Read the file content as text
155 const content = (await fs.readFile("utf-8")) as string;
156 const port = Number.parseInt(content.trim(), 10);
157
158 if (!Number.isFinite(port) || port <= 0 || port > 65535) {
159 return null;
160 }
161
162 return port;
163 } catch {
164 // File doesn't exist or couldn't be read
165 return null;
166 }
167}
168
169/**
170 * Get the port for a running LSP server from the axs port file.

Callers 1

getLspPortFunction · 0.85

Calls 3

fsOperationFunction · 0.85
existsMethod · 0.65
readFileMethod · 0.45

Tested by

no test coverage detected