This commit is contained in:
Kyle Kelley
2024-12-10 09:21:04 -08:00
parent baf90b31c9
commit 80c2f9dc6c
5 changed files with 27 additions and 20 deletions

1
Cargo.lock generated
View File

@@ -16012,7 +16012,6 @@ dependencies = [
"outline_panel",
"parking_lot",
"paths",
"picker",
"profiling",
"project",
"project_panel",

View File

@@ -1,6 +1,5 @@
use crate::kernels::KernelSpecification;
use crate::repl_store::ReplStore;
use crate::worktree_id_for_editor;
use crate::KERNEL_DOCS_URL;
use editor::Editor;
@@ -19,7 +18,7 @@ use ui::ListItemSpacing;
use gpui::SharedString;
use gpui::Task;
use ui::{prelude::*, ListItem, PopoverMenu, PopoverMenuHandle, PopoverTrigger};
use ui::{prelude::*, ListItem, PopoverMenu, PopoverMenuHandle};
pub type OnSelect = Box<dyn Fn(KernelSpecification, &mut WindowContext)>;
@@ -49,10 +48,11 @@ fn truncate_path(path: &SharedString, max_length: usize) -> SharedString {
}
impl KernelSelector {
pub fn new(editor: WeakView<Editor>, cx: &mut ViewContext<Self>) -> Self {
// todo!()
let worktree_id = worktree_id_for_editor(editor.clone(), cx).unwrap();
pub fn new(
worktree_id: WorktreeId,
editor: WeakView<Editor>,
_cx: &mut ViewContext<Self>,
) -> Self {
KernelSelector {
editor,
handle: None,
@@ -324,7 +324,6 @@ impl KernelPickerDelegate {
}
fn set_group(&mut self, group: Group, cx: &mut ViewContext<Picker<Self>>) {
dbg!(&group);
self.group = group;
cx.notify();
}

View File

@@ -80,7 +80,6 @@ outline.workspace = true
outline_panel.workspace = true
parking_lot.workspace = true
paths.workspace = true
picker.workspace = true
profiling.workspace = true
project.workspace = true
project_panel.workspace = true

View File

@@ -13,6 +13,7 @@ use gpui::{
Action, AnchorCorner, ClickEvent, ElementId, EventEmitter, FocusHandle, FocusableView,
InteractiveElement, ParentElement, Render, Styled, Subscription, View, ViewContext, WeakView,
};
use repl::worktree_id_for_editor;
use repl_menu::ReplMenu;
use search::{buffer_search, BufferSearchBar};
use settings::{Settings, SettingsStore};
@@ -428,8 +429,15 @@ impl ToolbarItemView for QuickActionBar {
if let Some(active_item) = active_pane_item {
self._inlay_hints_enabled_subscription.take();
if let Some(editor) = active_item.downcast::<Editor>() {
self.repl_menu = Some(cx.new_view(|cx| ReplMenu::new(editor.downgrade(), cx)));
let editor = active_item.downcast::<Editor>();
let work_tree_id = active_item
.downcast::<Editor>()
.and_then(|editor| worktree_id_for_editor(editor.downgrade(), cx));
if let (Some(editor), Some(work_tree_id)) = (editor, work_tree_id) {
self.repl_menu =
Some(cx.new_view(|cx| ReplMenu::new(work_tree_id, editor.downgrade(), cx)));
let mut inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
let mut supports_inlay_hints = editor.read(cx).supports_inlay_hints(cx);
self._inlay_hints_enabled_subscription =

View File

@@ -3,16 +3,14 @@ use std::time::Duration;
use editor::Editor;
use gpui::{percentage, Animation, AnimationExt, AnyElement, Transformation, View};
use gpui::{ElementId, WeakView};
use picker::Picker;
use repl::components::OnSelect;
use project::WorktreeId;
use repl::{
components::{KernelPickerDelegate, KernelSelector},
worktree_id_for_editor, ExecutionState, JupyterSettings, Kernel, KernelSpecification,
components::KernelSelector, ExecutionState, JupyterSettings, Kernel, KernelSpecification,
KernelStatus, Session, SessionSupport,
};
use ui::{
prelude::*, ButtonLike, ContextMenu, IconWithIndicator, Indicator, IntoElement, PopoverMenu,
PopoverMenuHandle, Tooltip,
Tooltip,
};
use util::ResultExt;
@@ -37,9 +35,13 @@ pub struct ReplMenu {
}
impl ReplMenu {
pub fn new(editor: WeakView<Editor>, cx: &mut ViewContext<Self>) -> Self {
pub fn new(
work_tree_id: WorktreeId,
editor: WeakView<Editor>,
cx: &mut ViewContext<Self>,
) -> Self {
Self {
kernel_menu: cx.new_view(|cx| KernelSelector::new(editor.clone(), cx)),
kernel_menu: cx.new_view(|cx| KernelSelector::new(work_tree_id, editor.clone(), cx)),
active_editor: editor.clone(),
}
}
@@ -279,7 +281,7 @@ impl ReplMenu {
pub fn render_repl_launch_menu(
&self,
kernel_specification: KernelSpecification,
cx: &mut ViewContext<Self>,
_cx: &mut ViewContext<Self>,
) -> impl IntoElement {
let tooltip: SharedString =
SharedString::from(format!("Start REPL for {}", kernel_specification.name()));
@@ -294,7 +296,7 @@ impl ReplMenu {
)
}
pub fn render_repl_setup(&self, language: &str, cx: &mut ViewContext<Self>) -> AnyElement {
pub fn render_repl_setup(&self, language: &str, _cx: &mut ViewContext<Self>) -> AnyElement {
let tooltip: SharedString = SharedString::from(format!("Setup Zed REPL for {}", language));
h_flex()
.child(self.kernel_menu.clone())