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