Skip to content

Commit

Permalink
Fix calculation of working dir (#16293)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Dec 17, 2024
1 parent 3fe87cd commit 52f33dc
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/kernels/raw/session/rawKernelSessionFactory.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ export async function computeLocalWorkingDirectory(
fs: IFileSystem
): Promise<string | undefined> {
let suggestedDir = await doComputeLocalWorkingDirectory(resource, configService, fs);
if (suggestedDir && (await fs.exists(suggestedDir))) {
return suggestedDir.fsPath;
if (suggestedDir && (await fs.exists(vscode.Uri.file(suggestedDir)))) {
return suggestedDir;
} else if (resource && resource.scheme !== 'untitled' && (await fs.exists(resource))) {
// Combine the working directory with this file if possible.
suggestedDir = vscode.Uri.file(
expandWorkingDir(getFilePath(suggestedDir), resource, configService.getSettings(resource))
);
if (suggestedDir && (await fs.exists(suggestedDir))) {
return suggestedDir.fsPath;
const workingDir =
suggestedDir && suggestedDir.includes('${')
? suggestedDir
: suggestedDir
? getFilePath(vscode.Uri.file(suggestedDir))
: undefined;
const expandedWorkingDir = expandWorkingDir(workingDir, resource, configService.getSettings(resource));
if (await fs.exists(vscode.Uri.file(expandedWorkingDir))) {
return expandedWorkingDir;
}
}
}
Expand All @@ -109,8 +113,8 @@ async function doComputeLocalWorkingDirectory(
resource: Resource,
configService: IConfigurationService,
fs: IFileSystem
): Promise<vscode.Uri | undefined> {
let workingDir: vscode.Uri | undefined;
): Promise<string | undefined> {
let workingDir: string | undefined;
// For a local launch calculate the working directory that we should switch into
const settings = configService.getSettings(resource);
const fileRootStr = untildify(settings.notebookFileRoot);
Expand All @@ -123,24 +127,24 @@ async function doComputeLocalWorkingDirectory(
if (path.isAbsolute(fileRootStr)) {
if (await fs.exists(fileRoot)) {
// User setting is absolute and exists, use it
workingDir = fileRoot;
workingDir = fileRoot.fsPath;
} else {
// User setting is absolute and doesn't exist, use workspace
workingDir = workspaceFolderPath;
workingDir = workspaceFolderPath.fsPath;
}
} else if (!fileRootStr.includes('${')) {
// fileRoot is a relative path, combine it with the workspace folder
const combinedPath = vscode.Uri.joinPath(workspaceFolderPath, fileRootStr);
if (await fs.exists(combinedPath)) {
// combined path exists, use it
workingDir = combinedPath;
workingDir = combinedPath.fsPath;
} else {
// Combined path doesn't exist, use workspace
workingDir = workspaceFolderPath;
workingDir = workspaceFolderPath.fsPath;
}
} else {
// fileRoot is a variable that hasn't been expanded
workingDir = fileRoot;
workingDir = fileRootStr;
}
}
return workingDir;
Expand Down

0 comments on commit 52f33dc

Please sign in to comment.