(processId?: number)
| 87 | } |
| 88 | |
| 89 | async function inferWorkingDirectory(processId?: number) { |
| 90 | const inferredWd = processId && (await processTree.getWorkingDirectory(processId)); |
| 91 | |
| 92 | // If we couldn't infer the working directory, just use the first workspace folder |
| 93 | if (!inferredWd) { |
| 94 | return vscode.workspace.workspaceFolders?.[0].uri.fsPath; |
| 95 | } |
| 96 | |
| 97 | const packageRoot = await nearestDirectoryContaining(inferredWd, 'package.json'); |
| 98 | if (!packageRoot) { |
| 99 | return inferredWd; |
| 100 | } |
| 101 | |
| 102 | // Find the working directory package root. If the original inferred working |
| 103 | // directory was inside a workspace folder, don't go past that. |
| 104 | const parentWorkspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(inferredWd)); |
| 105 | return !parentWorkspaceFolder || isSubdirectoryOf(parentWorkspaceFolder.uri.fsPath, packageRoot) |
| 106 | ? packageRoot |
| 107 | : parentWorkspaceFolder.uri.fsPath; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Process picker command (for launch config variable). Returns a string in |
no test coverage detected