python: Re-land usage of source file path in toolchain picker (#31893)

This reverts commit 1e55e88c18.

Closes #ISSUE

Release Notes:

- Python toolchain selector now uses path to the closest pyproject.toml
as a basis for picking a toolchain. All files under the same
pyproject.toml (in filesystem hierarchy) will share a single virtual
environment. It is possible to have multiple Python virtual environments
selected for disjoint parts of the same project.
This commit is contained in:
Piotr Osiewicz 2025-06-02 18:29:06 +02:00 committed by GitHub
parent 2ebe16a52f
commit 9dd18e5ee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 195 additions and 92 deletions

View file

@ -158,7 +158,7 @@ impl ActiveToolchain {
let project = workspace
.read_with(cx, |this, _| this.project().clone())
.ok()?;
let toolchains = cx
let (toolchains, relative_path) = cx
.update(|_, cx| {
project.read(cx).available_toolchains(
ProjectPath {

View file

@ -10,7 +10,7 @@ use gpui::{
use language::{LanguageName, Toolchain, ToolchainList};
use picker::{Picker, PickerDelegate};
use project::{Project, ProjectPath, WorktreeId};
use std::{path::Path, sync::Arc};
use std::{borrow::Cow, path::Path, sync::Arc};
use ui::{HighlightedLabel, ListItem, ListItemSpacing, prelude::*};
use util::ResultExt;
use workspace::{ModalView, Workspace};
@ -172,18 +172,8 @@ impl ToolchainSelectorDelegate {
let relative_path = this
.read_with(cx, |this, _| this.delegate.relative_path.clone())
.ok()?;
let placeholder_text = format!(
"Select a {} for `{}`…",
term.to_lowercase(),
relative_path.to_string_lossy()
)
.into();
let _ = this.update_in(cx, move |this, window, cx| {
this.delegate.placeholder_text = placeholder_text;
this.refresh_placeholder(window, cx);
});
let available_toolchains = project
let (available_toolchains, relative_path) = project
.update(cx, |this, cx| {
this.available_toolchains(
ProjectPath {
@ -196,6 +186,21 @@ impl ToolchainSelectorDelegate {
})
.ok()?
.await?;
let pretty_path = {
let path = relative_path.to_string_lossy();
if path.is_empty() {
Cow::Borrowed("worktree root")
} else {
Cow::Owned(format!("`{}`", path))
}
};
let placeholder_text =
format!("Select a {} for {pretty_path}", term.to_lowercase(),).into();
let _ = this.update_in(cx, move |this, window, cx| {
this.delegate.relative_path = relative_path;
this.delegate.placeholder_text = placeholder_text;
this.refresh_placeholder(window, cx);
});
let _ = this.update_in(cx, move |this, window, cx| {
this.delegate.candidates = available_toolchains;