1use std::collections::HashMap;
2
3use editor::EditorSettings;
4use gpui::App;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
8
9#[derive(Debug, Default)]
10pub struct JupyterSettings {
11 pub kernel_selections: HashMap<String, String>,
12}
13
14impl JupyterSettings {
15 pub fn enabled(cx: &App) -> bool {
16 // In order to avoid a circular dependency between `editor` and `repl` crates,
17 // we put the `enable` flag on its settings.
18 // This allows the editor to set up context for key bindings/actions.
19 EditorSettings::jupyter_enabled(cx)
20 }
21}
22
23#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)]
24#[settings_key(key = "jupyter")]
25pub struct JupyterSettingsContent {
26 /// Default kernels to select for each language.
27 ///
28 /// Default: `{}`
29 pub kernel_selections: Option<HashMap<String, String>>,
30}
31
32impl Default for JupyterSettingsContent {
33 fn default() -> Self {
34 JupyterSettingsContent {
35 kernel_selections: Some(HashMap::new()),
36 }
37 }
38}
39
40impl Settings for JupyterSettings {
41 type FileContent = JupyterSettingsContent;
42
43 fn load(
44 sources: SettingsSources<Self::FileContent>,
45 _cx: &mut gpui::App,
46 ) -> anyhow::Result<Self>
47 where
48 Self: Sized,
49 {
50 let mut settings = JupyterSettings::default();
51
52 for value in sources.defaults_and_customizations() {
53 if let Some(source) = &value.kernel_selections {
54 for (k, v) in source {
55 settings.kernel_selections.insert(k.clone(), v.clone());
56 }
57 }
58 }
59
60 Ok(settings)
61 }
62
63 fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
64}