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