MCPcopy Create free account
hub / github.com/Snapchat/Valdi / inferWorkingDirectory

Function inferWorkingDirectory

valdi/vscode_debugger/src/ui/processPicker.ts:89–108  ·  view source on GitHub ↗
(processId?: number)

Source from the content-addressed store, hash-verified

87}
88
89async 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

Callers 1

resolveProcessIdFunction · 0.85

Calls 4

isSubdirectoryOfFunction · 0.90
fileMethod · 0.80
getWorkingDirectoryMethod · 0.65

Tested by

no test coverage detected