(path: string)
| 344 | } |
| 345 | |
| 346 | async function readIdeLockfile(path: string): Promise<IdeLockfileInfo | null> { |
| 347 | try { |
| 348 | const content = await getFsImplementation().readFile(path, { |
| 349 | encoding: 'utf-8', |
| 350 | }) |
| 351 | |
| 352 | let workspaceFolders: string[] = [] |
| 353 | let pid: number | undefined |
| 354 | let ideName: string | undefined |
| 355 | let useWebSocket = false |
| 356 | let runningInWindows = false |
| 357 | let authToken: string | undefined |
| 358 | |
| 359 | try { |
| 360 | const parsedContent = jsonParse(content) as LockfileJsonContent |
| 361 | if (parsedContent.workspaceFolders) { |
| 362 | workspaceFolders = parsedContent.workspaceFolders |
| 363 | } |
| 364 | pid = parsedContent.pid |
| 365 | ideName = parsedContent.ideName |
| 366 | useWebSocket = parsedContent.transport === 'ws' |
| 367 | runningInWindows = parsedContent.runningInWindows === true |
| 368 | authToken = parsedContent.authToken |
| 369 | } catch (_) { |
| 370 | // Older format- just a list of paths. |
| 371 | workspaceFolders = content.split('\n').map(line => line.trim()) |
| 372 | } |
| 373 | |
| 374 | // Extract the port from the filename (e.g., 12345.lock -> 12345) |
| 375 | const filename = path.split(pathSeparator).pop() |
| 376 | if (!filename) return null |
| 377 | |
| 378 | const port = filename.replace('.lock', '') |
| 379 | |
| 380 | return { |
| 381 | workspaceFolders, |
| 382 | port: parseInt(port), |
| 383 | pid, |
| 384 | ideName, |
| 385 | useWebSocket, |
| 386 | runningInWindows, |
| 387 | authToken, |
| 388 | } |
| 389 | } catch (error) { |
| 390 | logError(error as Error) |
| 391 | return null |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Checks if the IDE connection is responding by testing if the port is open |
no test coverage detected