jupyter_settings.rs

 1use std::collections::HashMap;
 2
 3use editor::EditorSettings;
 4use gpui::App;
 5use schemars::JsonSchema;
 6use serde::{Deserialize, Serialize};
 7use settings::{Settings, 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)]
24pub struct JupyterSettingsContent {
25    /// Default kernels to select for each language.
26    ///
27    /// Default: `{}`
28    pub kernel_selections: Option<HashMap<String, String>>,
29}
30
31impl Default for JupyterSettingsContent {
32    fn default() -> Self {
33        JupyterSettingsContent {
34            kernel_selections: Some(HashMap::new()),
35        }
36    }
37}
38
39impl Settings for JupyterSettings {
40    const KEY: Option<&'static str> = Some("jupyter");
41
42    type FileContent = JupyterSettingsContent;
43
44    fn load(
45        sources: SettingsSources<Self::FileContent>,
46        _cx: &mut gpui::App,
47    ) -> anyhow::Result<Self>
48    where
49        Self: Sized,
50    {
51        let mut settings = JupyterSettings::default();
52
53        for value in sources.defaults_and_customizations() {
54            if let Some(source) = &value.kernel_selections {
55                for (k, v) in source {
56                    settings.kernel_selections.insert(k.clone(), v.clone());
57                }
58            }
59        }
60
61        Ok(settings)
62    }
63
64    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
65}