diff --git a/src/features/projectManager.ts b/src/features/projectManager.ts index 632707d1..526d9a20 100644 --- a/src/features/projectManager.ts +++ b/src/features/projectManager.ts @@ -67,7 +67,21 @@ export class PythonProjectManagerImpl implements PythonProjectManager { // For each override, resolve its path and add as a project if not already present for (const o of overrides) { - const uri = Uri.file(path.resolve(w.uri.fsPath, o.path)); + let uriFromWorkspace: Uri | undefined = undefined; + // if override has a workspace property, resolve the path relative to that workspace + if (o.workspace) { + // + const workspaceFolder = workspaces.find((ws) => ws.name === o.workspace); + if (workspaceFolder) { + if (workspaceFolder.uri.toString() !== w.uri.toString()) { + continue; // skip if the workspace is not the same as the current workspace + } + uriFromWorkspace = Uri.file(path.resolve(workspaceFolder.uri.fsPath, o.path)); + } + } + const uri = uriFromWorkspace ? uriFromWorkspace : Uri.file(path.resolve(w.uri.fsPath, o.path)); + + // Check if the project already exists in the newProjects array if (!newProjects.some((p) => p.uri.toString() === uri.toString())) { newProjects.push(new PythonProjectsImpl(o.path, uri)); } diff --git a/src/features/settings/settingHelpers.ts b/src/features/settings/settingHelpers.ts index d44ab77c..79ff8877 100644 --- a/src/features/settings/settingHelpers.ts +++ b/src/features/settings/settingHelpers.ts @@ -10,7 +10,7 @@ import { import { PythonProject } from '../../api'; import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants'; import { traceError, traceInfo } from '../../common/logging'; -import { getWorkspaceFile } from '../../common/workspace.apis'; +import { getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis'; import { PythonProjectManager, PythonProjectSettings } from '../../internal.api'; function getSettings( @@ -284,6 +284,7 @@ export interface EditProjectSettings { project: PythonProject; envManager?: string; packageManager?: string; + workspace?: string; } export async function addPythonProjectSetting(edits: EditProjectSettings[]): Promise { @@ -306,13 +307,23 @@ export async function addPythonProjectSetting(edits: EditProjectSettings[]): Pro traceError(`Unable to find workspace for ${e.project.uri.fsPath}`); }); + const isMultiroot = (getWorkspaceFolders() ?? []).length > 1; + const promises: Thenable[] = []; workspaces.forEach((es, w) => { const config = workspace.getConfiguration('python-envs', w.uri); const overrides = config.get('pythonProjects', []); es.forEach((e) => { + if (isMultiroot) { + } const pwPath = path.normalize(e.project.uri.fsPath); - const index = overrides.findIndex((s) => path.resolve(w.uri.fsPath, s.path) === pwPath); + const index = overrides.findIndex((s) => { + if (s.workspace) { + // If the workspace is set, check workspace and path in existing overrides + return s.workspace === w.name && path.resolve(w.uri.fsPath, s.path) === pwPath; + } + return path.resolve(w.uri.fsPath, s.path) === pwPath; + }); if (index >= 0) { overrides[index].envManager = e.envManager ?? envManager; overrides[index].packageManager = e.packageManager ?? pkgManager; @@ -321,6 +332,7 @@ export async function addPythonProjectSetting(edits: EditProjectSettings[]): Pro path: path.relative(w.uri.fsPath, pwPath).replace(/\\/g, '/'), envManager, packageManager: pkgManager, + workspace: isMultiroot ? w.name : undefined, }); } }); diff --git a/src/internal.api.ts b/src/internal.api.ts index 668fe3fa..6aad61b4 100644 --- a/src/internal.api.ts +++ b/src/internal.api.ts @@ -295,6 +295,7 @@ export interface PythonProjectSettings { path: string; envManager: string; packageManager: string; + workspace?: string; } export class PythonEnvironmentImpl implements PythonEnvironment {