Skip to content

Commit c77ea47

Browse files
Runtimes UI Starter (#13625)
Initial runtimes UI panel. The main draw here is that all message subscription occurs with two background tasks that run for the life of the kernel. Follow on to #12062 * [x] Disable previous cmd-enter behavior only if runtimes are enabled in settings * [x] Only show the runtimes panel if it is enabled via settings * [x] Create clean UI for the current sessions ### Running Kernels UI <img width="205" alt="image" src="https://github.com/zed-industries/zed/assets/836375/814ae79b-0807-4e23-bc95-77ce64f9d732"> * [x] List running kernels * [x] Implement shutdown * [x] Delete connection file on `drop` of `RunningKernel` * [x] Implement interrupt #### Project-specific Kernel Settings - [x] Modify JupyterSettings to include a `kernel_selections` field (`HashMap<String, String>`). - [x] Implement saving and loading of kernel selections to/from `.zed/settings.json` (by default, rather than global settings?) #### Kernel Selection Persistence - [x] Save the selected kernel for each language when the user makes a choice. - [x] Load these selections when the RuntimePanel is initialized. #### Use Selected Kernels - [x] Modify kernel launch to use the selected kernel for the detected language. - [x] Fallback to default behavior if no selection is made. ### Empty states - [x] Create helpful UI for when the user has 0 kernels they can launch and/or 0 kernels running <img width="694" alt="image" src="https://github.com/zed-industries/zed/assets/836375/d6a75939-e4e4-40fb-80fe-014da041cc3c"> ## Future work ### Kernel Discovery - Improve the kernel discovery process to handle various installation methods (system, virtualenv, poetry, etc.). - Create a way to refresh the available kernels on demand ### Documentation: - Update documentation to explain how users can configure kernels for their projects. - Provide examples of .zed/settings.json configurations for kernel selection. ### Kernel Selection UI - Implement a new section in the RuntimePanel to display available kernels. - Group on the language name from the kernel specification - Create a dropdown for each language group to select the default kernel. Release Notes: - N/A --------- Co-authored-by: Kirill <[email protected]>
1 parent 821aa08 commit c77ea47

File tree

12 files changed

+1438
-965
lines changed

12 files changed

+1438
-965
lines changed

crates/editor/src/editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12719,7 +12719,7 @@ pub(crate) fn split_words(text: &str) -> impl std::iter::Iterator<Item = &str> +
1271912719
})
1272012720
}
1272112721

12722-
trait RangeToAnchorExt {
12722+
pub trait RangeToAnchorExt {
1272312723
fn to_anchors(self, snapshot: &MultiBufferSnapshot) -> Range<Anchor>;
1272412724
}
1272512725

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
use std::collections::HashMap;
2+
3+
use schemars::JsonSchema;
4+
use serde::{Deserialize, Serialize};
5+
use settings::{Settings, SettingsSources};
6+
use ui::Pixels;
7+
8+
#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
9+
#[serde(rename_all = "snake_case")]
10+
pub enum JupyterDockPosition {
11+
Left,
12+
#[default]
13+
Right,
14+
Bottom,
15+
}
16+
17+
#[derive(Debug, Default)]
18+
pub struct JupyterSettings {
19+
pub enabled: bool,
20+
pub dock: JupyterDockPosition,
21+
pub default_width: Pixels,
22+
pub kernel_selections: HashMap<String, String>,
23+
}
24+
25+
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
26+
pub struct JupyterSettingsContent {
27+
/// Whether the Jupyter feature is enabled.
28+
///
29+
/// Default: `false`
30+
enabled: Option<bool>,
31+
/// Where to dock the Jupyter panel.
32+
///
33+
/// Default: `right`
34+
dock: Option<JupyterDockPosition>,
35+
/// Default width in pixels when the jupyter panel is docked to the left or right.
36+
///
37+
/// Default: 640
38+
pub default_width: Option<f32>,
39+
/// Default kernels to select for each language.
40+
///
41+
/// Default: `{}`
42+
pub kernel_selections: Option<HashMap<String, String>>,
43+
}
44+
45+
impl JupyterSettingsContent {
46+
pub fn set_dock(&mut self, dock: JupyterDockPosition) {
47+
self.dock = Some(dock);
48+
}
49+
}
50+
51+
impl Default for JupyterSettingsContent {
52+
fn default() -> Self {
53+
JupyterSettingsContent {
54+
enabled: Some(false),
55+
dock: Some(JupyterDockPosition::Right),
56+
default_width: Some(640.0),
57+
kernel_selections: Some(HashMap::new()),
58+
}
59+
}
60+
}
61+
62+
impl Settings for JupyterSettings {
63+
const KEY: Option<&'static str> = Some("jupyter");
64+
65+
type FileContent = JupyterSettingsContent;
66+
67+
fn load(
68+
sources: SettingsSources<Self::FileContent>,
69+
_cx: &mut gpui::AppContext,
70+
) -> anyhow::Result<Self>
71+
where
72+
Self: Sized,
73+
{
74+
let mut settings = JupyterSettings::default();
75+
76+
for value in sources.defaults_and_customizations() {
77+
if let Some(enabled) = value.enabled {
78+
settings.enabled = enabled;
79+
}
80+
if let Some(dock) = value.dock {
81+
settings.dock = dock;
82+
}
83+
84+
if let Some(default_width) = value.default_width {
85+
settings.default_width = Pixels::from(default_width);
86+
}
87+
88+
if let Some(source) = &value.kernel_selections {
89+
for (k, v) in source {
90+
settings.kernel_selections.insert(k.clone(), v.clone());
91+
}
92+
}
93+
}
94+
95+
Ok(settings)
96+
}
97+
}
98+
99+
#[cfg(test)]
100+
mod tests {
101+
use gpui::{AppContext, UpdateGlobal};
102+
use settings::SettingsStore;
103+
104+
use super::*;
105+
106+
#[gpui::test]
107+
fn test_deserialize_jupyter_settings(cx: &mut AppContext) {
108+
let store = settings::SettingsStore::test(cx);
109+
cx.set_global(store);
110+
111+
JupyterSettings::register(cx);
112+
113+
assert_eq!(JupyterSettings::get_global(cx).enabled, false);
114+
assert_eq!(
115+
JupyterSettings::get_global(cx).dock,
116+
JupyterDockPosition::Right
117+
);
118+
assert_eq!(
119+
JupyterSettings::get_global(cx).default_width,
120+
Pixels::from(640.0)
121+
);
122+
123+
// Setting a custom setting through user settings
124+
SettingsStore::update_global(cx, |store, cx| {
125+
store
126+
.set_user_settings(
127+
r#"{
128+
"jupyter": {
129+
"enabled": true,
130+
"dock": "left",
131+
"default_width": 800.0
132+
}
133+
}"#,
134+
cx,
135+
)
136+
.unwrap();
137+
});
138+
139+
assert_eq!(JupyterSettings::get_global(cx).enabled, true);
140+
assert_eq!(
141+
JupyterSettings::get_global(cx).dock,
142+
JupyterDockPosition::Left
143+
);
144+
assert_eq!(
145+
JupyterSettings::get_global(cx).default_width,
146+
Pixels::from(800.0)
147+
);
148+
}
149+
}

0 commit comments

Comments
 (0)