1mod language;
2mod theme;
3pub use language::*;
4pub use theme::*;
5
6use std::env;
7
8use collections::HashMap;
9use gpui::{App, SharedString};
10use release_channel::ReleaseChannel;
11use schemars::JsonSchema;
12use serde::{Deserialize, Serialize};
13
14use crate::ActiveSettingsProfileName;
15
16#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
17pub struct SettingsContent {
18 #[serde(flatten)]
19 pub project: ProjectSettingsContent,
20
21 #[serde(flatten)]
22 pub theme: ThemeSettingsContent,
23
24 // todo!() comments?!
25 pub base_keymap: Option<BaseKeymapContent>,
26
27 pub auto_update: Option<bool>,
28
29 pub title_bar: Option<TitleBarSettingsContent>,
30
31 /// Whether or not to enable Vim mode.
32 ///
33 /// Default: false
34 pub vim_mode: Option<bool>,
35 /// Whether or not to enable Helix mode.
36 ///
37 /// Default: false
38 pub helix_mode: Option<bool>,
39}
40
41impl SettingsContent {
42 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
43 &mut self.project.all_languages.languages.0
44 }
45}
46
47// todo!() what should this be?
48#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
49pub struct ServerSettingsContent {
50 #[serde(flatten)]
51 pub project: ProjectSettingsContent,
52}
53
54#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
55pub struct UserSettingsContent {
56 #[serde(flatten)]
57 pub content: SettingsContent,
58
59 pub dev: Option<SettingsContent>,
60 pub nightly: Option<SettingsContent>,
61 pub preview: Option<SettingsContent>,
62 pub stable: Option<SettingsContent>,
63
64 pub macos: Option<SettingsContent>,
65 pub windows: Option<SettingsContent>,
66 pub linux: Option<SettingsContent>,
67
68 #[serde(default)]
69 pub profiles: HashMap<String, SettingsContent>,
70}
71
72pub struct ExtensionsSettingsContent {
73 pub all_languages: AllLanguageSettingsContent,
74}
75
76impl UserSettingsContent {
77 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
78 match *release_channel::RELEASE_CHANNEL {
79 ReleaseChannel::Dev => self.dev.as_ref(),
80 ReleaseChannel::Nightly => self.nightly.as_ref(),
81 ReleaseChannel::Preview => self.preview.as_ref(),
82 ReleaseChannel::Stable => self.stable.as_ref(),
83 }
84 }
85
86 pub fn for_os(&self) -> Option<&SettingsContent> {
87 match env::consts::OS {
88 "macos" => self.macos.as_ref(),
89 "linux" => self.linux.as_ref(),
90 "windows" => self.windows.as_ref(),
91 _ => None,
92 }
93 }
94
95 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
96 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
97 return None;
98 };
99 self.profiles.get(&active_profile.0)
100 }
101}
102
103/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
104///
105/// Default: VSCode
106#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
107pub enum BaseKeymapContent {
108 #[default]
109 VSCode,
110 JetBrains,
111 SublimeText,
112 Atom,
113 TextMate,
114 Emacs,
115 Cursor,
116 None,
117}
118
119#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
120pub struct ProjectSettingsContent {
121 #[serde(flatten)]
122 pub(crate) all_languages: AllLanguageSettingsContent,
123}
124
125#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
126pub struct TitleBarSettingsContent {
127 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
128 ///
129 /// Default: "always"
130 pub show: Option<TitleBarVisibilityContent>,
131 /// Whether to show the branch icon beside branch switcher in the title bar.
132 ///
133 /// Default: false
134 pub show_branch_icon: Option<bool>,
135 /// Whether to show onboarding banners in the title bar.
136 ///
137 /// Default: true
138 pub show_onboarding_banner: Option<bool>,
139 /// Whether to show user avatar in the title bar.
140 ///
141 /// Default: true
142 pub show_user_picture: Option<bool>,
143 /// Whether to show the branch name button in the titlebar.
144 ///
145 /// Default: true
146 pub show_branch_name: Option<bool>,
147 /// Whether to show the project host and name in the titlebar.
148 ///
149 /// Default: true
150 pub show_project_items: Option<bool>,
151 /// Whether to show the sign in button in the title bar.
152 ///
153 /// Default: true
154 pub show_sign_in: Option<bool>,
155 /// Whether to show the menus in the title bar.
156 ///
157 /// Default: false
158 pub show_menus: Option<bool>,
159}
160
161#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
162#[serde(rename_all = "snake_case")]
163pub enum TitleBarVisibilityContent {
164 Always,
165 Never,
166 HideInFullScreen,
167}