Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group interpreters in interpreter quick picker using separators #18171

Merged
merged 24 commits into from
Jan 13, 2022

Conversation

karrtikr
Copy link

@karrtikr karrtikr commented Dec 13, 2021

Closes #17944

This PR changes interpreter sorting and autoselection a bit.

image

Comment on lines -177 to -189
switch (envType) {
case EnvironmentType.Venv:
case EnvironmentType.Conda:
case EnvironmentType.VirtualEnv:
case EnvironmentType.VirtualEnvWrapper:
case EnvironmentType.Pipenv:
case EnvironmentType.Poetry:
return EnvTypeHeuristic.Global;
// The default case covers global environments.
// For now this includes: pyenv, Windows Store, Global, System and Unknown environment types.
default:
return EnvTypeHeuristic.GlobalInterpreters;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make sure environments of the same type appear together, so they can be grouped. But in this all global environment types were assigned the same priority, so order was not guaranteed.

EnvironmentType.VirtualEnvWrapper,
EnvironmentType.Venv,
EnvironmentType.VirtualEnv,
EnvironmentType.Conda,
Copy link
Author

@karrtikr karrtikr Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead we assign each type a unique priority, conda being the last in the priority queue.

return 1;
}

if (!isCondaEnvironment(a) && isCondaEnvironment(b)) {
if (isBaseCondaEnvironment(b)) {
return -1;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled by getPrioritizedEnvironmentType() instead.

@karrtikr karrtikr marked this pull request as ready for review January 11, 2022 10:22
Comment on lines +206 to +209
const recommendedInterpreter = this.envTypeComparer.getRecommended(interpreters, workspaceUri?.folderUri);
if (!recommendedInterpreter) {
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored it out as we also need this info while showing the recommended interpreter in the list.

Comment on lines +129 to +131
export function setEnvDisplayString(env: PythonEnvInfo): void {
env.display = buildEnvDisplayString(env);
env.detailedDisplayName = buildEnvDisplayString(env, true);
Copy link
Author

@karrtikr karrtikr Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need type info in the display name when group name already contains a type. For eg.

image

Whereas if it's the "Workspace" group for instance we need the type info as group name doesn't contain type:

image

Hence 2 properties to carry display name.

// When recommending an intepreter for a workspace, we either want to return a local one
// or fallback on a globally-installed interpreter, and we don't want want to suggest a global environment
// because we would have to add a way to match environments to a workspace.
const workspaceUri = this.interpreterHelper.getActiveWorkspaceUri(resource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good item for debt week, we can remove the dependency on the interpreterHelper. What we really need here is the workspace uri, which is the real data. instead of depending on the object that provides that data.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we directly query vscode.workspace.getWorkspaceFolder API instead of using interpreter helper? (and get rid of the interpreter helper)

Interpreter helper also handles the case when resource is undefined, I guess that's why it's useful.

this.setRecommendedItem(interpreterSuggestions, resource);
suggestions.push(...interpreterSuggestions);
return suggestions;
}

private getSuggestions(resource: Resource): QuickPickType[] {
const workspaceFolder = this.workspaceService.getWorkspaceFolder(resource);
const items = this.interpreterSelector.getSuggestions(resource, !!this.interpreterService.refreshPromise);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to run this.interpreterSelector.getSuggestions twice looks a bit strange. How expensive is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It simply gets value from cache and sorts it, so not expensive at all.

@karrtikr karrtikr merged commit b929726 into microsoft:main Jan 13, 2022
@karrtikr karrtikr deleted the grouplist branch January 13, 2022 18:23
wesm pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
…osoft/vscode-python#18171)

* Group interpreters in interpreter quick picker using separators

* Do not group while the list is loading

* Cleanup

* Ensure full display name does not have arch for non-global type envs

* tes

* Recommend the same interpreter we autoselect

* Fix env resikver tst

* Fix display name testS

* Fix status bar display

* Fix autoselection tests

* Fix interpreter selector tests

* Fix sorting/do not prioritize conda envs

* Recommend Pipenv & Poetry envs

* Do not autoselect poetry/pipenv envs

* Fix interpreter selector tests

* Fix set interpreter tests

* News

* Add test for grouping

* Events to add an environment are handled appropriately if a grouped list is present

* Code reviews

* Add a new group for recommended interpreter

* Localize group names

* Fix unit tests

* Change quickpick list placeholder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Horizontal separators in Python interpreter list
4 participants