(config: ResolvingNodeAttachConfiguration, setCwd = false)
| 58 | * if it was cancelled. |
| 59 | */ |
| 60 | export async function resolveProcessId(config: ResolvingNodeAttachConfiguration, setCwd = false) { |
| 61 | // we resolve Process Picker early (before VS Code) so that we can probe the process for its protocol |
| 62 | const processId = config.processId?.trim(); |
| 63 | const result = processId && decodePidAndPort(processId); |
| 64 | if (!result || isNaN(result.pid)) { |
| 65 | throw new Error( |
| 66 | localize( |
| 67 | 'process.id.error', |
| 68 | "Attach to process: '{0}' doesn't look like a process id.", |
| 69 | processId, |
| 70 | ), |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | if (!result.port) { |
| 75 | putPidInDebugMode(result.pid); |
| 76 | } |
| 77 | |
| 78 | config.port = result.port || INSPECTOR_PORT_DEFAULT; |
| 79 | delete config.processId; |
| 80 | |
| 81 | if (setCwd) { |
| 82 | const inferredWd = await inferWorkingDirectory(result.pid); |
| 83 | if (inferredWd) { |
| 84 | config.cwd = inferredWd; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | async function inferWorkingDirectory(processId?: number) { |
| 90 | const inferredWd = processId && (await processTree.getWorkingDirectory(processId)); |
no test coverage detected