Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2 Fixes/16893.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix environment sorting for the `Python: Select Interpreter` command.
(thanks [Marc Mueller](https://github.com/cdce8p))
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ function compareEnvironmentType(a: PythonEnvironment, b: PythonEnvironment, work
export function getEnvTypeHeuristic(environment: PythonEnvironment, workspacePath: string): EnvTypeHeuristic {
const { envType } = environment;

if (workspacePath.length > 0 && environment.envPath && isParentPath(environment.envPath, workspacePath)) {
if (
workspacePath.length > 0 &&
((environment.envPath && isParentPath(environment.envPath, workspacePath)) ||
(environment.path && isParentPath(environment.path, workspacePath)))
) {
return EnvTypeHeuristic.Local;
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/configuration/environmentTypeComparer.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ suite('getEnvTypeHeuristic tests', () => {

assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Global);
});

test('If envPath is not set, fallback to path', () => {
const environment = {
envType,
path: path.join(workspacePath, 'my-environment'),
version: { major: 3, minor: 10, patch: 2 },
} as PythonEnvironment;

const envTypeHeuristic = getEnvTypeHeuristic(environment, workspacePath);

assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Local);
});
});

const globalInterpretersEnvTypes = [
Expand Down