python: Fix toolchains not getting picked up after workspace deserialization (#20488)
Closes #20476 Release Notes: - Fixed a bug in toolchain selector that caused it to not pick up venvs for tabs before user interacted with them. - Fixed a bug in language selector that caused it to pick up Markdown as the language for a buffer up until the tab was interacted with.
This commit is contained in:
parent
be8cc1146a
commit
45bbfe077a
2 changed files with 9 additions and 18 deletions
|
@ -66,7 +66,7 @@ impl StatusItemView for ActiveBufferLanguage {
|
||||||
active_pane_item: Option<&dyn ItemHandle>,
|
active_pane_item: Option<&dyn ItemHandle>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
if let Some(editor) = active_pane_item.and_then(|item| item.act_as::<Editor>(cx)) {
|
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
|
||||||
self._observe_active_editor = Some(cx.observe(&editor, Self::update_language));
|
self._observe_active_editor = Some(cx.observe(&editor, Self::update_language));
|
||||||
self.update_language(editor, cx);
|
self.update_language(editor, cx);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, AsyncWindowContext, EventEmitter, IntoElement, ParentElement, Render, Subscription, Task,
|
div, AsyncWindowContext, IntoElement, ParentElement, Render, Subscription, Task, View,
|
||||||
View, ViewContext, WeakModel, WeakView,
|
ViewContext, WeakModel, WeakView,
|
||||||
};
|
};
|
||||||
use language::{Buffer, BufferEvent, LanguageName, Toolchain};
|
use language::{Buffer, BufferEvent, LanguageName, Toolchain};
|
||||||
use project::WorktreeId;
|
use project::WorktreeId;
|
||||||
|
@ -14,24 +14,16 @@ pub struct ActiveToolchain {
|
||||||
active_toolchain: Option<Toolchain>,
|
active_toolchain: Option<Toolchain>,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
active_buffer: Option<(WorktreeId, WeakModel<Buffer>, Subscription)>,
|
active_buffer: Option<(WorktreeId, WeakModel<Buffer>, Subscription)>,
|
||||||
_observe_language_changes: Subscription,
|
|
||||||
_update_toolchain_task: Task<Option<()>>,
|
_update_toolchain_task: Task<Option<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LanguageChanged;
|
|
||||||
|
|
||||||
impl EventEmitter<LanguageChanged> for ActiveToolchain {}
|
|
||||||
|
|
||||||
impl ActiveToolchain {
|
impl ActiveToolchain {
|
||||||
pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
|
pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
|
||||||
let view = cx.view().clone();
|
|
||||||
Self {
|
Self {
|
||||||
active_toolchain: None,
|
active_toolchain: None,
|
||||||
active_buffer: None,
|
active_buffer: None,
|
||||||
workspace: workspace.weak_handle(),
|
workspace: workspace.weak_handle(),
|
||||||
_observe_language_changes: cx.subscribe(&view, |this, _, _: &LanguageChanged, cx| {
|
|
||||||
this._update_toolchain_task = Self::spawn_tracker_task(cx);
|
|
||||||
}),
|
|
||||||
_update_toolchain_task: Self::spawn_tracker_task(cx),
|
_update_toolchain_task: Self::spawn_tracker_task(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +40,6 @@ impl ActiveToolchain {
|
||||||
let workspace = this
|
let workspace = this
|
||||||
.update(&mut cx, |this, _| this.workspace.clone())
|
.update(&mut cx, |this, _| this.workspace.clone())
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
let language_name = active_file
|
let language_name = active_file
|
||||||
.update(&mut cx, |this, _| Some(this.language()?.name()))
|
.update(&mut cx, |this, _| Some(this.language()?.name()))
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -73,13 +64,13 @@ impl ActiveToolchain {
|
||||||
let editor = editor.read(cx);
|
let editor = editor.read(cx);
|
||||||
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
|
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
|
||||||
if let Some(worktree_id) = buffer.read(cx).file().map(|file| file.worktree_id(cx)) {
|
if let Some(worktree_id) = buffer.read(cx).file().map(|file| file.worktree_id(cx)) {
|
||||||
let subscription = cx.subscribe(&buffer, |_, _, event: &BufferEvent, cx| {
|
let subscription = cx.subscribe(&buffer, |this, _, event: &BufferEvent, cx| {
|
||||||
if let BufferEvent::LanguageChanged = event {
|
if matches!(event, BufferEvent::LanguageChanged) {
|
||||||
cx.emit(LanguageChanged)
|
this._update_toolchain_task = Self::spawn_tracker_task(cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.active_buffer = Some((worktree_id, buffer.downgrade(), subscription));
|
self.active_buffer = Some((worktree_id, buffer.downgrade(), subscription));
|
||||||
cx.emit(LanguageChanged);
|
self._update_toolchain_task = Self::spawn_tracker_task(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +155,7 @@ impl StatusItemView for ActiveToolchain {
|
||||||
active_pane_item: Option<&dyn ItemHandle>,
|
active_pane_item: Option<&dyn ItemHandle>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
if let Some(editor) = active_pane_item.and_then(|item| item.act_as::<Editor>(cx)) {
|
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
|
||||||
self.active_toolchain.take();
|
self.active_toolchain.take();
|
||||||
self.update_lister(editor, cx);
|
self.update_lister(editor, cx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue