|
3 | 3 |
|
4 | 4 | import { toLower, uniq, uniqBy } from 'lodash'; |
5 | 5 | import * as path from 'path'; |
| 6 | +import { Uri } from 'vscode'; |
6 | 7 | import { chain, iterable } from '../../../../common/utils/async'; |
7 | 8 | import { getEnvironmentVariable, getOSType, getUserHomeDir, OSType } from '../../../../common/utils/platform'; |
8 | 9 | import { PythonEnvKind } from '../../info'; |
9 | 10 | import { BasicEnvInfo, IPythonEnvsIterator } from '../../locator'; |
10 | 11 | import { FSWatchingLocator } from './fsWatchingLocator'; |
11 | 12 | import { findInterpretersInDir, looksLikeBasicVirtualPython } from '../../../common/commonUtils'; |
12 | 13 | import { pathExists, untildify } from '../../../common/externalDependencies'; |
13 | | -import { isPipenvEnvironment } from '../../../common/environmentManagers/pipenv'; |
| 14 | +import { getProjectDir, isPipenvEnvironment } from '../../../common/environmentManagers/pipenv'; |
14 | 15 | import { |
15 | 16 | isVenvEnvironment, |
16 | 17 | isVirtualenvEnvironment, |
@@ -57,6 +58,18 @@ async function getGlobalVirtualEnvDirs(): Promise<string[]> { |
57 | 58 | return [OSType.Windows, OSType.OSX].includes(getOSType()) ? uniqBy(venvDirs, toLower) : uniq(venvDirs); |
58 | 59 | } |
59 | 60 |
|
| 61 | +async function getSearchLocation(env: BasicEnvInfo): Promise<Uri | undefined> { |
| 62 | + if (env.kind === PythonEnvKind.Pipenv) { |
| 63 | + // Pipenv environments are created only for a specific project, so they must only |
| 64 | + // appear if that particular project is being queried. |
| 65 | + const project = await getProjectDir(path.dirname(path.dirname(env.executablePath))); |
| 66 | + if (project) { |
| 67 | + return Uri.file(project); |
| 68 | + } |
| 69 | + } |
| 70 | + return undefined; |
| 71 | +} |
| 72 | + |
60 | 73 | /** |
61 | 74 | * Gets the virtual environment kind for a given interpreter path. |
62 | 75 | * This only checks for environments created using venv, virtualenv, |
@@ -123,8 +136,9 @@ export class GlobalVirtualEnvironmentLocator extends FSWatchingLocator { |
123 | 136 | // check multiple times. Those checks are file system heavy and |
124 | 137 | // we can use the kind to determine this anyway. |
125 | 138 | const kind = await getVirtualEnvKind(filename); |
| 139 | + const searchLocation = await getSearchLocation({ kind, executablePath: filename }); |
126 | 140 | try { |
127 | | - yield { kind, executablePath: filename }; |
| 141 | + yield { kind, executablePath: filename, searchLocation }; |
128 | 142 | traceVerbose(`Global Virtual Environment: [added] ${filename}`); |
129 | 143 | } catch (ex) { |
130 | 144 | traceError(`Failed to process environment: ${filename}`, ex); |
|
0 commit comments