settings_content.rs

  1mod agent;
  2mod language;
  3mod project;
  4mod terminal;
  5mod theme;
  6pub use agent::*;
  7pub use language::*;
  8pub use project::*;
  9pub use terminal::*;
 10pub use theme::*;
 11
 12use collections::HashMap;
 13use gpui::{App, SharedString};
 14use release_channel::ReleaseChannel;
 15use schemars::JsonSchema;
 16use serde::{Deserialize, Serialize};
 17use std::env;
 18pub use util::serde::default_true;
 19
 20use crate::ActiveSettingsProfileName;
 21
 22#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize, JsonSchema)]
 23pub struct SettingsContent {
 24    #[serde(flatten)]
 25    pub project: ProjectSettingsContent,
 26
 27    #[serde(flatten)]
 28    pub theme: ThemeSettingsContent,
 29
 30    pub agent: Option<AgentSettingsContent>,
 31    pub agent_servers: Option<AllAgentServersSettings>,
 32
 33    /// Configuration of audio in Zed.
 34    pub audio: Option<AudioSettingsContent>,
 35    pub auto_update: Option<bool>,
 36
 37    // todo!() comments?!
 38    pub base_keymap: Option<BaseKeymapContent>,
 39
 40    pub debugger: Option<DebuggerSettingsContent>,
 41
 42    /// Configuration for Diagnostics-related features.
 43    pub diagnostics: Option<DiagnosticsSettingsContent>,
 44
 45    /// Configuration for Git-related features
 46    pub git: Option<GitSettings>,
 47
 48    /// Common language server settings.
 49    pub global_lsp_settings: Option<GlobalLspSettingsContent>,
 50
 51    /// Whether or not to enable Helix mode.
 52    ///
 53    /// Default: false
 54    pub helix_mode: Option<bool>,
 55    /// A map of log scopes to the desired log level.
 56    /// Useful for filtering out noisy logs or enabling more verbose logging.
 57    ///
 58    /// Example: {"log": {"client": "warn"}}
 59    pub log: Option<HashMap<String, String>>,
 60
 61    /// Configuration for Node-related features
 62    pub node: Option<NodeBinarySettings>,
 63
 64    pub proxy: Option<String>,
 65
 66    /// The URL of the Zed server to connect to.
 67    pub server_url: Option<String>,
 68
 69    /// Configuration for session-related features
 70    pub session: Option<SessionSettingsContent>,
 71    /// Control what info is collected by Zed.
 72    pub telemetry: Option<TelemetrySettingsContent>,
 73
 74    /// Configuration of the terminal in Zed.
 75    pub terminal: Option<TerminalSettingsContent>,
 76
 77    pub title_bar: Option<TitleBarSettingsContent>,
 78
 79    /// Whether or not to enable Vim mode.
 80    ///
 81    /// Default: false
 82    pub vim_mode: Option<bool>,
 83
 84    // Settings related to calls in Zed
 85    pub calls: Option<CallSettingsContent>,
 86
 87    /// Whether to disable all AI features in Zed.
 88    ///
 89    /// Default: false
 90    pub disable_ai: Option<bool>,
 91}
 92
 93impl SettingsContent {
 94    pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
 95        &mut self.project.all_languages.languages.0
 96    }
 97}
 98
 99// todo!() what should this be?
100#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
101pub struct ServerSettingsContent {
102    #[serde(flatten)]
103    pub project: ProjectSettingsContent,
104}
105
106#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
107pub struct UserSettingsContent {
108    #[serde(flatten)]
109    pub content: SettingsContent,
110
111    pub dev: Option<SettingsContent>,
112    pub nightly: Option<SettingsContent>,
113    pub preview: Option<SettingsContent>,
114    pub stable: Option<SettingsContent>,
115
116    pub macos: Option<SettingsContent>,
117    pub windows: Option<SettingsContent>,
118    pub linux: Option<SettingsContent>,
119
120    #[serde(default)]
121    pub profiles: HashMap<String, SettingsContent>,
122}
123
124pub struct ExtensionsSettingsContent {
125    pub all_languages: AllLanguageSettingsContent,
126}
127
128impl UserSettingsContent {
129    pub fn for_release_channel(&self) -> Option<&SettingsContent> {
130        match *release_channel::RELEASE_CHANNEL {
131            ReleaseChannel::Dev => self.dev.as_ref(),
132            ReleaseChannel::Nightly => self.nightly.as_ref(),
133            ReleaseChannel::Preview => self.preview.as_ref(),
134            ReleaseChannel::Stable => self.stable.as_ref(),
135        }
136    }
137
138    pub fn for_os(&self) -> Option<&SettingsContent> {
139        match env::consts::OS {
140            "macos" => self.macos.as_ref(),
141            "linux" => self.linux.as_ref(),
142            "windows" => self.windows.as_ref(),
143            _ => None,
144        }
145    }
146
147    pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
148        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
149            return None;
150        };
151        self.profiles.get(&active_profile.0)
152    }
153}
154
155/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
156///
157/// Default: VSCode
158#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
159pub enum BaseKeymapContent {
160    #[default]
161    VSCode,
162    JetBrains,
163    SublimeText,
164    Atom,
165    TextMate,
166    Emacs,
167    Cursor,
168    None,
169}
170
171#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
172pub struct TitleBarSettingsContent {
173    /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
174    ///
175    /// Default: "always"
176    pub show: Option<TitleBarVisibilityContent>,
177    /// Whether to show the branch icon beside branch switcher in the title bar.
178    ///
179    /// Default: false
180    pub show_branch_icon: Option<bool>,
181    /// Whether to show onboarding banners in the title bar.
182    ///
183    /// Default: true
184    pub show_onboarding_banner: Option<bool>,
185    /// Whether to show user avatar in the title bar.
186    ///
187    /// Default: true
188    pub show_user_picture: Option<bool>,
189    /// Whether to show the branch name button in the titlebar.
190    ///
191    /// Default: true
192    pub show_branch_name: Option<bool>,
193    /// Whether to show the project host and name in the titlebar.
194    ///
195    /// Default: true
196    pub show_project_items: Option<bool>,
197    /// Whether to show the sign in button in the title bar.
198    ///
199    /// Default: true
200    pub show_sign_in: Option<bool>,
201    /// Whether to show the menus in the title bar.
202    ///
203    /// Default: false
204    pub show_menus: Option<bool>,
205}
206
207#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
208#[serde(rename_all = "snake_case")]
209pub enum TitleBarVisibilityContent {
210    Always,
211    Never,
212    HideInFullScreen,
213}
214
215/// Configuration of audio in Zed.
216#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
217pub struct AudioSettingsContent {
218    /// Opt into the new audio system.
219    #[serde(rename = "experimental.rodio_audio", default)]
220    pub rodio_audio: Option<bool>,
221    /// Requires 'rodio_audio: true'
222    ///
223    /// Use the new audio systems automatic gain control for your microphone.
224    /// This affects how loud you sound to others.
225    #[serde(rename = "experimental.control_input_volume", default)]
226    pub control_input_volume: Option<bool>,
227    /// Requires 'rodio_audio: true'
228    ///
229    /// Use the new audio systems automatic gain control on everyone in the
230    /// call. This makes call members who are too quite louder and those who are
231    /// too loud quieter. This only affects how things sound for you.
232    #[serde(rename = "experimental.control_output_volume", default)]
233    pub control_output_volume: Option<bool>,
234}
235
236/// Control what info is collected by Zed.
237#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Debug)]
238pub struct TelemetrySettingsContent {
239    /// Send debug info like crash reports.
240    ///
241    /// Default: true
242    pub diagnostics: Option<bool>,
243    /// Send anonymized usage data like what languages you're using Zed with.
244    ///
245    /// Default: true
246    pub metrics: Option<bool>,
247}
248
249#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Clone)]
250pub struct DebuggerSettingsContent {
251    /// Determines the stepping granularity.
252    ///
253    /// Default: line
254    pub stepping_granularity: Option<SteppingGranularity>,
255    /// Whether the breakpoints should be reused across Zed sessions.
256    ///
257    /// Default: true
258    pub save_breakpoints: Option<bool>,
259    /// Whether to show the debug button in the status bar.
260    ///
261    /// Default: true
262    pub button: Option<bool>,
263    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
264    ///
265    /// Default: 2000ms
266    pub timeout: Option<u64>,
267    /// Whether to log messages between active debug adapters and Zed
268    ///
269    /// Default: true
270    pub log_dap_communications: Option<bool>,
271    /// Whether to format dap messages in when adding them to debug adapter logger
272    ///
273    /// Default: true
274    pub format_dap_log_messages: Option<bool>,
275    /// The dock position of the debug panel
276    ///
277    /// Default: Bottom
278    pub dock: Option<DockPosition>,
279}
280
281/// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.
282#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy, Deserialize, Serialize, JsonSchema)]
283#[serde(rename_all = "snake_case")]
284pub enum SteppingGranularity {
285    /// The step should allow the program to run until the current statement has finished executing.
286    /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
287    /// For example 'for(int i = 0; i < 10; i++)' could be considered to have 3 statements 'int i = 0', 'i < 10', and 'i++'.
288    Statement,
289    /// The step should allow the program to run until the current source line has executed.
290    Line,
291    /// The step should allow one instruction to execute (e.g. one x86 instruction).
292    Instruction,
293}
294
295#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
296#[serde(rename_all = "snake_case")]
297pub enum DockPosition {
298    Left,
299    Bottom,
300    Right,
301}
302
303/// Settings for slash commands.
304#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, PartialEq, Eq)]
305pub struct SlashCommandSettings {
306    /// Settings for the `/cargo-workspace` slash command.
307    pub cargo_workspace: Option<CargoWorkspaceCommandSettings>,
308}
309
310/// Settings for the `/cargo-workspace` slash command.
311#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, PartialEq, Eq)]
312pub struct CargoWorkspaceCommandSettings {
313    /// Whether `/cargo-workspace` is enabled.
314    pub enabled: Option<bool>,
315}
316
317/// Configuration of voice calls in Zed.
318#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
319pub struct CallSettingsContent {
320    /// Whether the microphone should be muted when joining a channel or a call.
321    ///
322    /// Default: false
323    pub mute_on_join: Option<bool>,
324
325    /// Whether your current project should be shared when joining an empty channel.
326    ///
327    /// Default: false
328    pub share_on_join: Option<bool>,
329}