Skip to content

Commit a477bed

Browse files
cdce8pkarthiknadig
andauthored
Fallback to path for environmentTypeComparer (#16893)
* Fallback to path for environmentTypeComparer * Add news entry * Update news/2 Fixes/16893.md Co-authored-by: Karthik Nadig <[email protected]> Co-authored-by: Karthik Nadig <[email protected]>
1 parent d3212e4 commit a477bed

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

news/2 Fixes/16893.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix environment sorting for the `Python: Select Interpreter` command.
2+
(thanks [Marc Mueller](https://github.com/cdce8p))

src/client/interpreter/configuration/environmentTypeComparer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ function compareEnvironmentType(a: PythonEnvironment, b: PythonEnvironment, work
168168
export function getEnvTypeHeuristic(environment: PythonEnvironment, workspacePath: string): EnvTypeHeuristic {
169169
const { envType } = environment;
170170

171-
if (workspacePath.length > 0 && environment.envPath && isParentPath(environment.envPath, workspacePath)) {
171+
if (
172+
workspacePath.length > 0 &&
173+
((environment.envPath && isParentPath(environment.envPath, workspacePath)) ||
174+
(environment.path && isParentPath(environment.path, workspacePath)))
175+
) {
172176
return EnvTypeHeuristic.Local;
173177
}
174178

src/test/configuration/environmentTypeComparer.unit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ suite('getEnvTypeHeuristic tests', () => {
266266

267267
assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Global);
268268
});
269+
270+
test('If envPath is not set, fallback to path', () => {
271+
const environment = {
272+
envType,
273+
path: path.join(workspacePath, 'my-environment'),
274+
version: { major: 3, minor: 10, patch: 2 },
275+
} as PythonEnvironment;
276+
277+
const envTypeHeuristic = getEnvTypeHeuristic(environment, workspacePath);
278+
279+
assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Local);
280+
});
269281
});
270282

271283
const globalInterpretersEnvTypes = [

0 commit comments

Comments
 (0)