2022-04-11 23:50:44 +00:00
|
|
|
mod keymap_file;
|
2023-05-10 01:14:42 +00:00
|
|
|
mod settings_file;
|
|
|
|
mod settings_store;
|
2022-04-11 22:22:18 +00:00
|
|
|
|
2023-05-10 01:14:42 +00:00
|
|
|
use anyhow::bail;
|
2022-07-12 18:00:02 +00:00
|
|
|
use gpui::{
|
|
|
|
font_cache::{FamilyId, FontCache},
|
2023-05-10 01:14:42 +00:00
|
|
|
fonts, AppContext, AssetSource,
|
2022-07-12 18:00:02 +00:00
|
|
|
};
|
2022-04-07 23:00:51 +00:00
|
|
|
use schemars::{
|
2023-05-10 16:56:58 +00:00
|
|
|
gen::SchemaGenerator,
|
2022-07-12 19:19:01 +00:00
|
|
|
schema::{InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec},
|
2022-04-07 23:00:51 +00:00
|
|
|
JsonSchema,
|
|
|
|
};
|
2023-05-10 01:14:42 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-04-08 01:15:02 +00:00
|
|
|
use serde_json::Value;
|
2023-05-10 01:14:42 +00:00
|
|
|
use settings_store::Setting;
|
2022-11-14 21:18:44 +00:00
|
|
|
use sqlez::{
|
2023-01-23 04:33:21 +00:00
|
|
|
bindable::{Bind, Column, StaticColumnCount},
|
2022-11-14 21:18:44 +00:00
|
|
|
statement::Statement,
|
|
|
|
};
|
2023-05-10 01:14:42 +00:00
|
|
|
use std::{borrow::Cow, collections::HashMap, num::NonZeroU32, path::Path, str, sync::Arc};
|
2022-04-06 00:10:17 +00:00
|
|
|
use theme::{Theme, ThemeRegistry};
|
2023-05-10 01:14:42 +00:00
|
|
|
use util::ResultExt as _;
|
2022-04-06 00:10:17 +00:00
|
|
|
|
2022-04-21 20:33:39 +00:00
|
|
|
pub use keymap_file::{keymap_file_json_schema, KeymapFileContent};
|
2023-05-10 01:14:42 +00:00
|
|
|
pub use settings_file::*;
|
2023-05-10 16:56:58 +00:00
|
|
|
pub use settings_store::{SettingsJsonSchemaParams, SettingsStore};
|
2022-04-11 23:50:44 +00:00
|
|
|
|
2023-05-03 02:56:45 +00:00
|
|
|
pub const DEFAULT_SETTINGS_ASSET_PATH: &str = "settings/default.json";
|
|
|
|
pub const INITIAL_USER_SETTINGS_ASSET_PATH: &str = "settings/initial_user_settings.json";
|
|
|
|
|
2022-04-06 00:10:17 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Settings {
|
2023-04-19 18:07:05 +00:00
|
|
|
pub features: Features,
|
2023-03-17 08:51:07 +00:00
|
|
|
pub buffer_font_family_name: String,
|
|
|
|
pub buffer_font_features: fonts::Features,
|
2022-04-06 00:10:17 +00:00
|
|
|
pub buffer_font_family: FamilyId,
|
2022-05-27 20:02:52 +00:00
|
|
|
pub default_buffer_font_size: f32,
|
2022-07-16 01:27:10 +00:00
|
|
|
pub buffer_font_size: f32,
|
2022-10-26 00:24:19 +00:00
|
|
|
pub active_pane_magnification: f32,
|
2022-10-17 23:19:03 +00:00
|
|
|
pub cursor_blink: bool,
|
2023-01-20 21:02:38 +00:00
|
|
|
pub confirm_quit: bool,
|
2022-06-27 23:21:22 +00:00
|
|
|
pub hover_popover_enabled: bool,
|
2022-07-12 20:09:01 +00:00
|
|
|
pub show_completions_on_input: bool,
|
2023-01-31 23:17:16 +00:00
|
|
|
pub show_call_status_icon: bool,
|
2022-04-06 00:10:17 +00:00
|
|
|
pub vim_mode: bool,
|
2022-07-05 11:01:27 +00:00
|
|
|
pub autosave: Autosave,
|
2022-09-09 02:32:38 +00:00
|
|
|
pub default_dock_anchor: DockAnchor,
|
2022-07-12 18:42:43 +00:00
|
|
|
pub editor_defaults: EditorSettings,
|
|
|
|
pub editor_overrides: EditorSettings,
|
2022-10-03 18:53:33 +00:00
|
|
|
pub git: GitSettings,
|
2022-10-03 19:42:30 +00:00
|
|
|
pub git_overrides: GitSettings,
|
2023-04-28 01:06:52 +00:00
|
|
|
pub copilot: CopilotSettings,
|
2022-09-28 20:25:37 +00:00
|
|
|
pub journal_defaults: JournalSettings,
|
|
|
|
pub journal_overrides: JournalSettings,
|
2022-07-16 01:27:10 +00:00
|
|
|
pub terminal_defaults: TerminalSettings,
|
|
|
|
pub terminal_overrides: TerminalSettings,
|
2022-07-12 18:42:43 +00:00
|
|
|
pub language_defaults: HashMap<Arc<str>, EditorSettings>,
|
|
|
|
pub language_overrides: HashMap<Arc<str>, EditorSettings>,
|
2022-08-04 02:32:18 +00:00
|
|
|
pub lsp: HashMap<Arc<str>, LspSettings>,
|
2022-04-06 00:10:17 +00:00
|
|
|
pub theme: Arc<Theme>,
|
2023-01-10 23:06:48 +00:00
|
|
|
pub telemetry_defaults: TelemetrySettings,
|
|
|
|
pub telemetry_overrides: TelemetrySettings,
|
2023-02-15 02:05:42 +00:00
|
|
|
pub auto_update: bool,
|
2023-03-08 01:13:01 +00:00
|
|
|
pub base_keymap: BaseKeymap,
|
2023-03-29 03:52:50 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 01:14:42 +00:00
|
|
|
impl Setting for Settings {
|
|
|
|
type FileContent = SettingsFileContent;
|
|
|
|
|
|
|
|
fn load(
|
|
|
|
defaults: &Self::FileContent,
|
|
|
|
user_values: &[&Self::FileContent],
|
|
|
|
cx: &AppContext,
|
|
|
|
) -> Self {
|
|
|
|
let buffer_font_features = defaults.buffer_font_features.clone().unwrap();
|
|
|
|
let themes = cx.global::<Arc<ThemeRegistry>>();
|
|
|
|
|
|
|
|
let mut this = Self {
|
|
|
|
buffer_font_family: cx
|
|
|
|
.font_cache()
|
|
|
|
.load_family(
|
|
|
|
&[defaults.buffer_font_family.as_ref().unwrap()],
|
|
|
|
&buffer_font_features,
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
buffer_font_family_name: defaults.buffer_font_family.clone().unwrap(),
|
|
|
|
buffer_font_features,
|
|
|
|
buffer_font_size: defaults.buffer_font_size.unwrap(),
|
|
|
|
active_pane_magnification: defaults.active_pane_magnification.unwrap(),
|
|
|
|
default_buffer_font_size: defaults.buffer_font_size.unwrap(),
|
|
|
|
confirm_quit: defaults.confirm_quit.unwrap(),
|
|
|
|
cursor_blink: defaults.cursor_blink.unwrap(),
|
|
|
|
hover_popover_enabled: defaults.hover_popover_enabled.unwrap(),
|
|
|
|
show_completions_on_input: defaults.show_completions_on_input.unwrap(),
|
|
|
|
show_call_status_icon: defaults.show_call_status_icon.unwrap(),
|
|
|
|
vim_mode: defaults.vim_mode.unwrap(),
|
|
|
|
autosave: defaults.autosave.unwrap(),
|
|
|
|
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
|
|
|
editor_defaults: EditorSettings {
|
|
|
|
tab_size: defaults.editor.tab_size,
|
|
|
|
hard_tabs: defaults.editor.hard_tabs,
|
|
|
|
soft_wrap: defaults.editor.soft_wrap,
|
|
|
|
preferred_line_length: defaults.editor.preferred_line_length,
|
|
|
|
remove_trailing_whitespace_on_save: defaults
|
|
|
|
.editor
|
|
|
|
.remove_trailing_whitespace_on_save,
|
|
|
|
ensure_final_newline_on_save: defaults.editor.ensure_final_newline_on_save,
|
|
|
|
format_on_save: defaults.editor.format_on_save.clone(),
|
|
|
|
formatter: defaults.editor.formatter.clone(),
|
|
|
|
enable_language_server: defaults.editor.enable_language_server,
|
|
|
|
show_copilot_suggestions: defaults.editor.show_copilot_suggestions,
|
|
|
|
show_whitespaces: defaults.editor.show_whitespaces,
|
|
|
|
},
|
|
|
|
editor_overrides: Default::default(),
|
|
|
|
copilot: CopilotSettings {
|
|
|
|
disabled_globs: defaults
|
|
|
|
.copilot
|
|
|
|
.clone()
|
|
|
|
.unwrap()
|
|
|
|
.disabled_globs
|
|
|
|
.unwrap()
|
|
|
|
.into_iter()
|
|
|
|
.map(|s| glob::Pattern::new(&s).unwrap())
|
|
|
|
.collect(),
|
|
|
|
},
|
|
|
|
git: defaults.git.unwrap(),
|
|
|
|
git_overrides: Default::default(),
|
|
|
|
journal_defaults: defaults.journal.clone(),
|
|
|
|
journal_overrides: Default::default(),
|
|
|
|
terminal_defaults: defaults.terminal.clone(),
|
|
|
|
terminal_overrides: Default::default(),
|
|
|
|
language_defaults: defaults.languages.clone(),
|
|
|
|
language_overrides: Default::default(),
|
|
|
|
lsp: defaults.lsp.clone(),
|
|
|
|
theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(),
|
|
|
|
telemetry_defaults: defaults.telemetry,
|
|
|
|
telemetry_overrides: Default::default(),
|
|
|
|
auto_update: defaults.auto_update.unwrap(),
|
|
|
|
base_keymap: Default::default(),
|
|
|
|
features: Features {
|
|
|
|
copilot: defaults.features.copilot.unwrap(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for value in user_values.into_iter().copied().cloned() {
|
|
|
|
this.set_user_settings(value, themes.as_ref(), cx.font_cache());
|
|
|
|
}
|
|
|
|
|
|
|
|
this
|
|
|
|
}
|
2023-05-10 16:56:58 +00:00
|
|
|
|
|
|
|
fn json_schema(
|
|
|
|
generator: &mut SchemaGenerator,
|
|
|
|
params: &SettingsJsonSchemaParams,
|
|
|
|
) -> schemars::schema::RootSchema {
|
|
|
|
let mut root_schema = generator.root_schema_for::<SettingsFileContent>();
|
|
|
|
|
|
|
|
// Create a schema for a theme name.
|
|
|
|
let theme_name_schema = SchemaObject {
|
|
|
|
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
|
|
|
enum_values: Some(
|
|
|
|
params
|
|
|
|
.theme_names
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.map(Value::String)
|
|
|
|
.collect(),
|
|
|
|
),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a schema for a 'languages overrides' object, associating editor
|
|
|
|
// settings with specific langauges.
|
|
|
|
assert!(root_schema.definitions.contains_key("EditorSettings"));
|
|
|
|
|
|
|
|
let languages_object_schema = SchemaObject {
|
|
|
|
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
|
|
|
|
object: Some(Box::new(ObjectValidation {
|
|
|
|
properties: params
|
|
|
|
.language_names
|
|
|
|
.iter()
|
|
|
|
.map(|name| {
|
|
|
|
(
|
|
|
|
name.clone(),
|
|
|
|
Schema::new_ref("#/definitions/EditorSettings".into()),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add these new schemas as definitions, and modify properties of the root
|
|
|
|
// schema to reference them.
|
|
|
|
root_schema.definitions.extend([
|
|
|
|
("ThemeName".into(), theme_name_schema.into()),
|
|
|
|
("Languages".into(), languages_object_schema.into()),
|
|
|
|
]);
|
|
|
|
let root_schema_object = &mut root_schema.schema.object.as_mut().unwrap();
|
|
|
|
|
|
|
|
root_schema_object.properties.extend([
|
|
|
|
(
|
|
|
|
"theme".to_owned(),
|
|
|
|
Schema::new_ref("#/definitions/ThemeName".into()),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"languages".to_owned(),
|
|
|
|
Schema::new_ref("#/definitions/Languages".into()),
|
|
|
|
),
|
|
|
|
// For backward compatibility
|
|
|
|
(
|
|
|
|
"language_overrides".to_owned(),
|
|
|
|
Schema::new_ref("#/definitions/Languages".into()),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
|
|
|
root_schema
|
|
|
|
}
|
2023-05-10 01:14:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 01:13:01 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
|
2023-03-07 20:19:51 +00:00
|
|
|
pub enum BaseKeymap {
|
2023-03-08 01:13:01 +00:00
|
|
|
#[default]
|
|
|
|
VSCode,
|
2023-03-07 20:19:51 +00:00
|
|
|
JetBrains,
|
2023-03-13 12:27:04 +00:00
|
|
|
SublimeText,
|
2023-03-07 20:19:51 +00:00
|
|
|
Atom,
|
2023-03-13 12:27:04 +00:00
|
|
|
TextMate,
|
2023-03-07 20:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BaseKeymap {
|
2023-03-13 12:27:04 +00:00
|
|
|
pub const OPTIONS: [(&'static str, Self); 5] = [
|
2023-03-08 01:13:01 +00:00
|
|
|
("VSCode (Default)", Self::VSCode),
|
|
|
|
("Atom", Self::Atom),
|
|
|
|
("JetBrains", Self::JetBrains),
|
2023-03-13 12:27:04 +00:00
|
|
|
("Sublime Text", Self::SublimeText),
|
|
|
|
("TextMate", Self::TextMate),
|
2023-03-08 01:13:01 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
pub fn asset_path(&self) -> Option<&'static str> {
|
2023-03-07 20:19:51 +00:00
|
|
|
match self {
|
2023-03-08 01:13:01 +00:00
|
|
|
BaseKeymap::JetBrains => Some("keymaps/jetbrains.json"),
|
2023-03-13 12:27:04 +00:00
|
|
|
BaseKeymap::SublimeText => Some("keymaps/sublime_text.json"),
|
2023-03-08 01:13:01 +00:00
|
|
|
BaseKeymap::Atom => Some("keymaps/atom.json"),
|
2023-03-13 12:27:04 +00:00
|
|
|
BaseKeymap::TextMate => Some("keymaps/textmate.json"),
|
2023-03-08 01:13:01 +00:00
|
|
|
BaseKeymap::VSCode => None,
|
2023-03-07 20:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 01:13:01 +00:00
|
|
|
|
|
|
|
pub fn names() -> impl Iterator<Item = &'static str> {
|
|
|
|
Self::OPTIONS.iter().map(|(name, _)| *name)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_names(option: &str) -> BaseKeymap {
|
|
|
|
Self::OPTIONS
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.find_map(|(name, value)| (name == option).then(|| value))
|
|
|
|
.unwrap_or_default()
|
|
|
|
}
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 23:06:48 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
|
|
|
pub struct TelemetrySettings {
|
|
|
|
diagnostics: Option<bool>,
|
|
|
|
metrics: Option<bool>,
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:49:54 +00:00
|
|
|
impl TelemetrySettings {
|
|
|
|
pub fn metrics(&self) -> bool {
|
|
|
|
self.metrics.unwrap()
|
|
|
|
}
|
2023-02-24 22:31:59 +00:00
|
|
|
|
2023-01-10 23:49:54 +00:00
|
|
|
pub fn diagnostics(&self) -> bool {
|
|
|
|
self.diagnostics.unwrap()
|
|
|
|
}
|
2023-02-24 22:31:59 +00:00
|
|
|
|
|
|
|
pub fn set_metrics(&mut self, value: bool) {
|
|
|
|
self.metrics = Some(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_diagnostics(&mut self, value: bool) {
|
|
|
|
self.diagnostics = Some(value);
|
|
|
|
}
|
2023-01-10 23:49:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 01:06:52 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct CopilotSettings {
|
|
|
|
pub disabled_globs: Vec<glob::Pattern>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
|
|
|
pub struct CopilotSettingsContent {
|
|
|
|
#[serde(default)]
|
2023-05-03 02:56:45 +00:00
|
|
|
pub disabled_globs: Option<Vec<String>>,
|
2023-04-28 01:06:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
2022-10-03 18:53:33 +00:00
|
|
|
pub struct GitSettings {
|
2022-10-03 19:11:06 +00:00
|
|
|
pub git_gutter: Option<GitGutter>,
|
2022-10-04 00:43:05 +00:00
|
|
|
pub gutter_debounce: Option<u64>,
|
2022-09-19 22:22:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
2022-09-19 22:22:39 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-10-04 00:43:05 +00:00
|
|
|
pub enum GitGutter {
|
2022-09-19 22:22:39 +00:00
|
|
|
#[default]
|
2022-10-04 00:43:05 +00:00
|
|
|
TrackedFiles,
|
|
|
|
Hide,
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 00:43:05 +00:00
|
|
|
pub struct GitGutterConfig {}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
2022-07-12 18:42:43 +00:00
|
|
|
pub struct EditorSettings {
|
2022-06-23 00:13:52 +00:00
|
|
|
pub tab_size: Option<NonZeroU32>,
|
2022-06-09 01:08:07 +00:00
|
|
|
pub hard_tabs: Option<bool>,
|
2022-04-06 00:10:17 +00:00
|
|
|
pub soft_wrap: Option<SoftWrap>,
|
|
|
|
pub preferred_line_length: Option<u32>,
|
2022-09-23 20:52:00 +00:00
|
|
|
pub format_on_save: Option<FormatOnSave>,
|
2023-02-27 20:14:18 +00:00
|
|
|
pub remove_trailing_whitespace_on_save: Option<bool>,
|
2023-02-27 22:32:08 +00:00
|
|
|
pub ensure_final_newline_on_save: Option<bool>,
|
2022-09-22 22:21:05 +00:00
|
|
|
pub formatter: Option<Formatter>,
|
2022-06-09 08:07:31 +00:00
|
|
|
pub enable_language_server: Option<bool>,
|
2023-04-19 18:07:05 +00:00
|
|
|
pub show_copilot_suggestions: Option<bool>,
|
2023-05-05 11:30:16 +00:00
|
|
|
pub show_whitespaces: Option<ShowWhitespaces>,
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-04-06 00:10:17 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum SoftWrap {
|
|
|
|
None,
|
|
|
|
EditorWidth,
|
|
|
|
PreferredLineLength,
|
|
|
|
}
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-09-23 20:52:00 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum FormatOnSave {
|
|
|
|
On,
|
|
|
|
Off,
|
|
|
|
LanguageServer,
|
|
|
|
External {
|
|
|
|
command: String,
|
|
|
|
arguments: Vec<String>,
|
|
|
|
},
|
|
|
|
}
|
2022-04-06 00:10:17 +00:00
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-07-07 09:03:37 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-09-22 22:21:05 +00:00
|
|
|
pub enum Formatter {
|
2022-07-07 09:03:37 +00:00
|
|
|
LanguageServer,
|
|
|
|
External {
|
|
|
|
command: String,
|
|
|
|
arguments: Vec<String>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-07-05 07:25:22 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum Autosave {
|
|
|
|
Off,
|
2022-07-05 11:01:27 +00:00
|
|
|
AfterDelay { milliseconds: u64 },
|
2022-07-05 07:25:22 +00:00
|
|
|
OnFocusChange,
|
|
|
|
OnWindowChange,
|
|
|
|
}
|
|
|
|
|
2022-10-16 16:51:34 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
2022-09-28 20:25:37 +00:00
|
|
|
pub struct JournalSettings {
|
2022-09-29 20:18:16 +00:00
|
|
|
pub path: Option<String>,
|
2022-09-28 20:25:37 +00:00
|
|
|
pub hour_format: Option<HourFormat>,
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:18:16 +00:00
|
|
|
impl Default for JournalSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: Some("~".into()),
|
|
|
|
hour_format: Some(Default::default()),
|
|
|
|
}
|
|
|
|
}
|
2022-09-28 20:25:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 16:51:48 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
2022-09-28 20:25:37 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum HourFormat {
|
|
|
|
Hour12,
|
|
|
|
Hour24,
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:18:16 +00:00
|
|
|
impl Default for HourFormat {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Hour12
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
2022-07-16 01:27:10 +00:00
|
|
|
pub struct TerminalSettings {
|
|
|
|
pub shell: Option<Shell>,
|
|
|
|
pub working_directory: Option<WorkingDirectory>,
|
|
|
|
pub font_size: Option<f32>,
|
|
|
|
pub font_family: Option<String>,
|
2023-04-21 00:24:27 +00:00
|
|
|
pub line_height: Option<TerminalLineHeight>,
|
2023-03-17 10:42:24 +00:00
|
|
|
pub font_features: Option<fonts::Features>,
|
2022-07-18 21:50:33 +00:00
|
|
|
pub env: Option<HashMap<String, String>>,
|
2022-08-16 01:05:07 +00:00
|
|
|
pub blinking: Option<TerminalBlink>,
|
2022-08-19 20:54:25 +00:00
|
|
|
pub alternate_scroll: Option<AlternateScroll>,
|
2022-09-13 05:40:35 +00:00
|
|
|
pub option_as_meta: Option<bool>,
|
2022-10-10 14:29:51 +00:00
|
|
|
pub copy_on_select: Option<bool>,
|
2022-08-16 01:05:07 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 00:24:27 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum TerminalLineHeight {
|
|
|
|
#[default]
|
|
|
|
Comfortable,
|
|
|
|
Standard,
|
|
|
|
Custom(f32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TerminalLineHeight {
|
|
|
|
fn value(&self) -> f32 {
|
|
|
|
match self {
|
|
|
|
TerminalLineHeight::Comfortable => 1.618,
|
|
|
|
TerminalLineHeight::Standard => 1.3,
|
|
|
|
TerminalLineHeight::Custom(line_height) => *line_height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-08-16 01:05:07 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum TerminalBlink {
|
2022-08-18 18:28:18 +00:00
|
|
|
Off,
|
2022-08-17 21:41:28 +00:00
|
|
|
TerminalControlled,
|
2022-08-18 18:28:18 +00:00
|
|
|
On,
|
2022-08-16 01:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TerminalBlink {
|
|
|
|
fn default() -> Self {
|
2022-08-17 21:41:28 +00:00
|
|
|
TerminalBlink::TerminalControlled
|
2022-08-16 01:05:07 +00:00
|
|
|
}
|
2022-07-16 01:27:10 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-07-16 01:27:10 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum Shell {
|
|
|
|
System,
|
|
|
|
Program(String),
|
|
|
|
WithArguments { program: String, args: Vec<String> },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Shell {
|
|
|
|
fn default() -> Self {
|
|
|
|
Shell::System
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:18:24 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-08-19 20:54:25 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum AlternateScroll {
|
|
|
|
On,
|
|
|
|
Off,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AlternateScroll {
|
|
|
|
fn default() -> Self {
|
|
|
|
AlternateScroll::On
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-07-16 01:27:10 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum WorkingDirectory {
|
|
|
|
CurrentProjectDirectory,
|
|
|
|
FirstProjectDirectory,
|
|
|
|
AlwaysHome,
|
|
|
|
Always { directory: String },
|
|
|
|
}
|
|
|
|
|
2022-12-09 00:10:22 +00:00
|
|
|
impl Default for WorkingDirectory {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::CurrentProjectDirectory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 00:24:27 +00:00
|
|
|
impl TerminalSettings {
|
|
|
|
fn line_height(&self) -> Option<f32> {
|
|
|
|
self.line_height
|
|
|
|
.to_owned()
|
|
|
|
.map(|line_height| line_height.value())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(PartialEq, Eq, Debug, Default, Copy, Clone, Hash, Serialize, Deserialize, JsonSchema)]
|
2022-09-09 02:32:38 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum DockAnchor {
|
|
|
|
#[default]
|
|
|
|
Bottom,
|
|
|
|
Right,
|
|
|
|
Expanded,
|
|
|
|
}
|
|
|
|
|
2023-01-23 04:33:21 +00:00
|
|
|
impl StaticColumnCount for DockAnchor {}
|
2022-11-14 21:18:44 +00:00
|
|
|
impl Bind for DockAnchor {
|
|
|
|
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
|
|
|
match self {
|
|
|
|
DockAnchor::Bottom => "Bottom",
|
|
|
|
DockAnchor::Right => "Right",
|
|
|
|
DockAnchor::Expanded => "Expanded",
|
|
|
|
}
|
|
|
|
.bind(statement, start_index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Column for DockAnchor {
|
|
|
|
fn column(statement: &mut Statement, start_index: i32) -> anyhow::Result<(Self, i32)> {
|
|
|
|
String::column(statement, start_index).and_then(|(anchor_text, next_index)| {
|
|
|
|
Ok((
|
|
|
|
match anchor_text.as_ref() {
|
|
|
|
"Bottom" => DockAnchor::Bottom,
|
|
|
|
"Right" => DockAnchor::Right,
|
|
|
|
"Expanded" => DockAnchor::Expanded,
|
|
|
|
_ => bail!("Stored dock anchor is incorrect"),
|
|
|
|
},
|
|
|
|
next_index,
|
|
|
|
))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
2022-04-06 00:10:17 +00:00
|
|
|
pub struct SettingsFileContent {
|
|
|
|
#[serde(default)]
|
|
|
|
pub buffer_font_family: Option<String>,
|
|
|
|
#[serde(default)]
|
|
|
|
pub buffer_font_size: Option<f32>,
|
|
|
|
#[serde(default)]
|
2023-03-17 08:51:07 +00:00
|
|
|
pub buffer_font_features: Option<fonts::Features>,
|
|
|
|
#[serde(default)]
|
2023-04-28 01:06:52 +00:00
|
|
|
pub copilot: Option<CopilotSettingsContent>,
|
|
|
|
#[serde(default)]
|
2022-10-26 00:24:19 +00:00
|
|
|
pub active_pane_magnification: Option<f32>,
|
|
|
|
#[serde(default)]
|
2022-10-17 23:19:03 +00:00
|
|
|
pub cursor_blink: Option<bool>,
|
|
|
|
#[serde(default)]
|
2023-01-20 21:02:38 +00:00
|
|
|
pub confirm_quit: Option<bool>,
|
|
|
|
#[serde(default)]
|
2022-06-27 23:21:22 +00:00
|
|
|
pub hover_popover_enabled: Option<bool>,
|
|
|
|
#[serde(default)]
|
2022-07-12 20:09:01 +00:00
|
|
|
pub show_completions_on_input: Option<bool>,
|
|
|
|
#[serde(default)]
|
2023-01-31 23:17:16 +00:00
|
|
|
pub show_call_status_icon: Option<bool>,
|
|
|
|
#[serde(default)]
|
2022-04-06 00:10:17 +00:00
|
|
|
pub vim_mode: Option<bool>,
|
2022-04-28 21:31:06 +00:00
|
|
|
#[serde(default)]
|
2022-07-05 11:01:27 +00:00
|
|
|
pub autosave: Option<Autosave>,
|
2022-09-09 02:32:38 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub default_dock_anchor: Option<DockAnchor>,
|
2022-04-06 00:10:17 +00:00
|
|
|
#[serde(flatten)]
|
2022-07-12 18:42:43 +00:00
|
|
|
pub editor: EditorSettings,
|
2022-04-06 00:10:17 +00:00
|
|
|
#[serde(default)]
|
2022-09-28 20:25:37 +00:00
|
|
|
pub journal: JournalSettings,
|
|
|
|
#[serde(default)]
|
2022-07-16 01:27:10 +00:00
|
|
|
pub terminal: TerminalSettings,
|
|
|
|
#[serde(default)]
|
2022-10-03 18:53:33 +00:00
|
|
|
pub git: Option<GitSettings>,
|
|
|
|
#[serde(default)]
|
2022-07-12 18:42:43 +00:00
|
|
|
#[serde(alias = "language_overrides")]
|
|
|
|
pub languages: HashMap<Arc<str>, EditorSettings>,
|
2022-04-06 00:10:17 +00:00
|
|
|
#[serde(default)]
|
2022-08-04 02:32:18 +00:00
|
|
|
pub lsp: HashMap<Arc<str>, LspSettings>,
|
|
|
|
#[serde(default)]
|
2022-04-06 00:10:17 +00:00
|
|
|
pub theme: Option<String>,
|
2022-09-08 23:27:46 +00:00
|
|
|
#[serde(default)]
|
2023-01-10 23:06:48 +00:00
|
|
|
pub telemetry: TelemetrySettings,
|
2023-02-15 02:05:42 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub auto_update: Option<bool>,
|
2023-03-07 20:19:51 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub base_keymap: Option<BaseKeymap>,
|
2023-03-29 03:52:50 +00:00
|
|
|
#[serde(default)]
|
2023-04-19 18:07:05 +00:00
|
|
|
pub features: FeaturesContent,
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 00:05:23 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
2022-08-04 02:32:18 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub struct LspSettings {
|
|
|
|
pub initialization_options: Option<Value>,
|
|
|
|
}
|
|
|
|
|
2023-04-28 01:06:52 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2023-04-19 18:07:05 +00:00
|
|
|
pub struct Features {
|
|
|
|
pub copilot: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub struct FeaturesContent {
|
|
|
|
pub copilot: Option<bool>,
|
|
|
|
}
|
|
|
|
|
2023-05-04 11:43:50 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2023-05-05 11:30:16 +00:00
|
|
|
pub enum ShowWhitespaces {
|
2023-05-04 11:43:50 +00:00
|
|
|
#[default]
|
2023-05-04 21:36:31 +00:00
|
|
|
Selection,
|
2023-05-04 11:43:50 +00:00
|
|
|
None,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
2022-04-06 00:10:17 +00:00
|
|
|
impl Settings {
|
2023-05-03 02:56:45 +00:00
|
|
|
pub fn initial_user_settings_content(assets: &'static impl AssetSource) -> Cow<'static, str> {
|
|
|
|
match assets.load(INITIAL_USER_SETTINGS_ASSET_PATH).unwrap() {
|
|
|
|
Cow::Borrowed(s) => Cow::Borrowed(str::from_utf8(s).unwrap()),
|
|
|
|
Cow::Owned(s) => Cow::Owned(String::from_utf8(s).unwrap()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:06:48 +00:00
|
|
|
/// Fill out the settings corresponding to the default.json file, overrides will be set later
|
2022-07-12 18:00:02 +00:00
|
|
|
pub fn defaults(
|
|
|
|
assets: impl AssetSource,
|
2022-04-06 00:10:17 +00:00
|
|
|
font_cache: &FontCache,
|
2022-07-12 18:00:02 +00:00
|
|
|
themes: &ThemeRegistry,
|
|
|
|
) -> Self {
|
2022-09-22 22:21:05 +00:00
|
|
|
#[track_caller]
|
2022-07-12 18:35:19 +00:00
|
|
|
fn required<T>(value: Option<T>) -> Option<T> {
|
|
|
|
assert!(value.is_some(), "missing default setting value");
|
|
|
|
value
|
|
|
|
}
|
|
|
|
|
2023-05-10 01:14:42 +00:00
|
|
|
let defaults: SettingsFileContent = settings_store::parse_json_with_comments(
|
2023-05-03 02:56:45 +00:00
|
|
|
str::from_utf8(assets.load(DEFAULT_SETTINGS_ASSET_PATH).unwrap().as_ref()).unwrap(),
|
2022-07-12 18:42:43 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2022-07-12 18:35:19 +00:00
|
|
|
|
2023-03-17 08:51:07 +00:00
|
|
|
let buffer_font_features = defaults.buffer_font_features.unwrap();
|
2022-07-12 18:00:02 +00:00
|
|
|
Self {
|
|
|
|
buffer_font_family: font_cache
|
2023-03-17 08:51:07 +00:00
|
|
|
.load_family(
|
|
|
|
&[defaults.buffer_font_family.as_ref().unwrap()],
|
2023-03-17 12:54:56 +00:00
|
|
|
&buffer_font_features,
|
2023-03-17 08:51:07 +00:00
|
|
|
)
|
2022-07-12 18:00:02 +00:00
|
|
|
.unwrap(),
|
2023-03-17 08:51:07 +00:00
|
|
|
buffer_font_family_name: defaults.buffer_font_family.unwrap(),
|
|
|
|
buffer_font_features,
|
2022-07-12 18:00:02 +00:00
|
|
|
buffer_font_size: defaults.buffer_font_size.unwrap(),
|
2022-10-26 00:24:19 +00:00
|
|
|
active_pane_magnification: defaults.active_pane_magnification.unwrap(),
|
2022-07-12 18:00:02 +00:00
|
|
|
default_buffer_font_size: defaults.buffer_font_size.unwrap(),
|
2023-01-20 21:02:38 +00:00
|
|
|
confirm_quit: defaults.confirm_quit.unwrap(),
|
2022-10-17 23:19:03 +00:00
|
|
|
cursor_blink: defaults.cursor_blink.unwrap(),
|
2022-07-12 18:00:02 +00:00
|
|
|
hover_popover_enabled: defaults.hover_popover_enabled.unwrap(),
|
2022-07-12 20:09:01 +00:00
|
|
|
show_completions_on_input: defaults.show_completions_on_input.unwrap(),
|
2023-01-31 23:17:16 +00:00
|
|
|
show_call_status_icon: defaults.show_call_status_icon.unwrap(),
|
2022-07-12 18:00:02 +00:00
|
|
|
vim_mode: defaults.vim_mode.unwrap(),
|
|
|
|
autosave: defaults.autosave.unwrap(),
|
2022-09-09 02:32:38 +00:00
|
|
|
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
2022-07-12 18:42:43 +00:00
|
|
|
editor_defaults: EditorSettings {
|
2022-07-12 18:35:19 +00:00
|
|
|
tab_size: required(defaults.editor.tab_size),
|
|
|
|
hard_tabs: required(defaults.editor.hard_tabs),
|
|
|
|
soft_wrap: required(defaults.editor.soft_wrap),
|
|
|
|
preferred_line_length: required(defaults.editor.preferred_line_length),
|
2023-02-27 20:14:18 +00:00
|
|
|
remove_trailing_whitespace_on_save: required(
|
|
|
|
defaults.editor.remove_trailing_whitespace_on_save,
|
|
|
|
),
|
2023-02-27 22:32:08 +00:00
|
|
|
ensure_final_newline_on_save: required(
|
|
|
|
defaults.editor.ensure_final_newline_on_save,
|
|
|
|
),
|
2022-07-12 18:35:19 +00:00
|
|
|
format_on_save: required(defaults.editor.format_on_save),
|
2022-09-22 22:21:05 +00:00
|
|
|
formatter: required(defaults.editor.formatter),
|
2022-07-12 18:35:19 +00:00
|
|
|
enable_language_server: required(defaults.editor.enable_language_server),
|
2023-04-19 18:07:05 +00:00
|
|
|
show_copilot_suggestions: required(defaults.editor.show_copilot_suggestions),
|
2023-05-05 11:30:16 +00:00
|
|
|
show_whitespaces: required(defaults.editor.show_whitespaces),
|
2022-07-12 18:00:02 +00:00
|
|
|
},
|
2022-07-12 18:35:19 +00:00
|
|
|
editor_overrides: Default::default(),
|
2023-05-03 02:56:45 +00:00
|
|
|
copilot: CopilotSettings {
|
|
|
|
disabled_globs: defaults
|
|
|
|
.copilot
|
|
|
|
.unwrap()
|
|
|
|
.disabled_globs
|
|
|
|
.unwrap()
|
|
|
|
.into_iter()
|
|
|
|
.map(|s| glob::Pattern::new(&s).unwrap())
|
|
|
|
.collect(),
|
|
|
|
},
|
2022-10-03 18:53:33 +00:00
|
|
|
git: defaults.git.unwrap(),
|
2022-10-03 19:42:30 +00:00
|
|
|
git_overrides: Default::default(),
|
2022-10-16 16:42:18 +00:00
|
|
|
journal_defaults: defaults.journal,
|
2022-09-28 20:25:37 +00:00
|
|
|
journal_overrides: Default::default(),
|
2022-10-10 14:29:51 +00:00
|
|
|
terminal_defaults: defaults.terminal,
|
2022-07-16 01:27:10 +00:00
|
|
|
terminal_overrides: Default::default(),
|
|
|
|
language_defaults: defaults.languages,
|
2022-04-06 00:10:17 +00:00
|
|
|
language_overrides: Default::default(),
|
2022-08-04 02:32:18 +00:00
|
|
|
lsp: defaults.lsp.clone(),
|
2022-07-12 18:00:02 +00:00
|
|
|
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
2023-01-10 23:06:48 +00:00
|
|
|
telemetry_defaults: defaults.telemetry,
|
|
|
|
telemetry_overrides: Default::default(),
|
2023-02-15 02:05:42 +00:00
|
|
|
auto_update: defaults.auto_update.unwrap(),
|
2023-03-07 20:19:51 +00:00
|
|
|
base_keymap: Default::default(),
|
2023-04-19 18:07:05 +00:00
|
|
|
features: Features {
|
|
|
|
copilot: defaults.features.copilot.unwrap(),
|
|
|
|
},
|
2022-07-12 18:00:02 +00:00
|
|
|
}
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 23:06:48 +00:00
|
|
|
// Fill out the overrride and etc. settings from the user's settings.json
|
2022-07-13 00:43:00 +00:00
|
|
|
pub fn set_user_settings(
|
|
|
|
&mut self,
|
|
|
|
data: SettingsFileContent,
|
|
|
|
theme_registry: &ThemeRegistry,
|
|
|
|
font_cache: &FontCache,
|
|
|
|
) {
|
2023-03-17 08:51:07 +00:00
|
|
|
let mut family_changed = false;
|
|
|
|
if let Some(value) = data.buffer_font_family {
|
|
|
|
self.buffer_font_family_name = value;
|
|
|
|
family_changed = true;
|
|
|
|
}
|
|
|
|
if let Some(value) = data.buffer_font_features {
|
|
|
|
self.buffer_font_features = value;
|
|
|
|
family_changed = true;
|
|
|
|
}
|
|
|
|
if family_changed {
|
|
|
|
if let Some(id) = font_cache
|
2023-03-17 12:54:56 +00:00
|
|
|
.load_family(&[&self.buffer_font_family_name], &self.buffer_font_features)
|
2023-03-17 08:51:07 +00:00
|
|
|
.log_err()
|
|
|
|
{
|
2022-07-13 00:43:00 +00:00
|
|
|
self.buffer_font_family = id;
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 08:51:07 +00:00
|
|
|
|
2022-07-13 00:43:00 +00:00
|
|
|
if let Some(value) = &data.theme {
|
2022-08-10 21:39:24 +00:00
|
|
|
if let Some(theme) = theme_registry.get(value).log_err() {
|
2022-07-13 00:43:00 +00:00
|
|
|
self.theme = theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
merge(&mut self.buffer_font_size, data.buffer_font_size);
|
2022-10-26 00:24:19 +00:00
|
|
|
merge(
|
|
|
|
&mut self.active_pane_magnification,
|
|
|
|
data.active_pane_magnification,
|
|
|
|
);
|
2022-07-13 00:43:00 +00:00
|
|
|
merge(&mut self.default_buffer_font_size, data.buffer_font_size);
|
2022-10-17 23:19:03 +00:00
|
|
|
merge(&mut self.cursor_blink, data.cursor_blink);
|
2023-01-20 21:02:38 +00:00
|
|
|
merge(&mut self.confirm_quit, data.confirm_quit);
|
2022-07-13 00:43:00 +00:00
|
|
|
merge(&mut self.hover_popover_enabled, data.hover_popover_enabled);
|
2022-07-13 21:29:47 +00:00
|
|
|
merge(
|
|
|
|
&mut self.show_completions_on_input,
|
|
|
|
data.show_completions_on_input,
|
|
|
|
);
|
2022-07-13 00:43:00 +00:00
|
|
|
merge(&mut self.vim_mode, data.vim_mode);
|
|
|
|
merge(&mut self.autosave, data.autosave);
|
2022-09-09 02:32:38 +00:00
|
|
|
merge(&mut self.default_dock_anchor, data.default_dock_anchor);
|
2023-03-08 01:13:01 +00:00
|
|
|
merge(&mut self.base_keymap, data.base_keymap);
|
2023-04-19 18:07:05 +00:00
|
|
|
merge(&mut self.features.copilot, data.features.copilot);
|
2022-09-09 02:32:38 +00:00
|
|
|
|
2023-05-03 02:56:45 +00:00
|
|
|
if let Some(copilot) = data.copilot {
|
|
|
|
if let Some(disabled_globs) = copilot.disabled_globs {
|
|
|
|
self.copilot.disabled_globs = disabled_globs
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|s| glob::Pattern::new(&s).ok())
|
|
|
|
.collect()
|
|
|
|
}
|
2023-04-28 01:06:52 +00:00
|
|
|
}
|
2022-07-13 00:43:00 +00:00
|
|
|
self.editor_overrides = data.editor;
|
2022-10-03 19:42:30 +00:00
|
|
|
self.git_overrides = data.git.unwrap_or_default();
|
2022-09-28 20:25:37 +00:00
|
|
|
self.journal_overrides = data.journal;
|
2022-07-16 01:27:10 +00:00
|
|
|
self.terminal_defaults.font_size = data.terminal.font_size;
|
2022-10-10 14:29:51 +00:00
|
|
|
self.terminal_overrides.copy_on_select = data.terminal.copy_on_select;
|
2022-07-16 01:27:10 +00:00
|
|
|
self.terminal_overrides = data.terminal;
|
2022-07-13 00:43:00 +00:00
|
|
|
self.language_overrides = data.languages;
|
2023-01-10 23:06:48 +00:00
|
|
|
self.telemetry_overrides = data.telemetry;
|
2022-08-04 02:32:18 +00:00
|
|
|
self.lsp = data.lsp;
|
2023-02-15 02:05:42 +00:00
|
|
|
merge(&mut self.auto_update, data.auto_update);
|
2022-07-13 00:43:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 14:40:57 +00:00
|
|
|
pub fn with_language_defaults(
|
2022-04-06 00:10:17 +00:00
|
|
|
mut self,
|
|
|
|
language_name: impl Into<Arc<str>>,
|
2022-07-12 18:42:43 +00:00
|
|
|
overrides: EditorSettings,
|
2022-04-06 00:10:17 +00:00
|
|
|
) -> Self {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_defaults
|
2022-04-06 00:10:17 +00:00
|
|
|
.insert(language_name.into(), overrides);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-04-19 18:07:05 +00:00
|
|
|
pub fn features(&self) -> &Features {
|
|
|
|
&self.features
|
|
|
|
}
|
|
|
|
|
2023-05-03 02:56:45 +00:00
|
|
|
pub fn show_copilot_suggestions(&self, language: Option<&str>, path: Option<&Path>) -> bool {
|
|
|
|
if !self.features.copilot {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !self.copilot_enabled_for_language(language) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(path) = path {
|
|
|
|
if !self.copilot_enabled_for_path(path) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn copilot_enabled_for_path(&self, path: &Path) -> bool {
|
|
|
|
!self
|
|
|
|
.copilot
|
|
|
|
.disabled_globs
|
|
|
|
.iter()
|
|
|
|
.any(|glob| glob.matches_path(path))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn copilot_enabled_for_language(&self, language: Option<&str>) -> bool {
|
|
|
|
self.language_setting(language, |settings| settings.show_copilot_suggestions)
|
2023-03-29 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 00:13:52 +00:00
|
|
|
pub fn tab_size(&self, language: Option<&str>) -> NonZeroU32 {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_setting(language, |settings| settings.tab_size)
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 11:30:16 +00:00
|
|
|
pub fn show_whitespaces(&self, language: Option<&str>) -> ShowWhitespaces {
|
|
|
|
self.language_setting(language, |settings| settings.show_whitespaces)
|
2023-05-04 11:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 01:08:07 +00:00
|
|
|
pub fn hard_tabs(&self, language: Option<&str>) -> bool {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_setting(language, |settings| settings.hard_tabs)
|
2022-06-09 01:08:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 00:10:17 +00:00
|
|
|
pub fn soft_wrap(&self, language: Option<&str>) -> SoftWrap {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_setting(language, |settings| settings.soft_wrap)
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn preferred_line_length(&self, language: Option<&str>) -> u32 {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_setting(language, |settings| settings.preferred_line_length)
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 20:14:18 +00:00
|
|
|
pub fn remove_trailing_whitespace_on_save(&self, language: Option<&str>) -> bool {
|
|
|
|
self.language_setting(language, |settings| {
|
|
|
|
settings.remove_trailing_whitespace_on_save.clone()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-27 22:32:08 +00:00
|
|
|
pub fn ensure_final_newline_on_save(&self, language: Option<&str>) -> bool {
|
|
|
|
self.language_setting(language, |settings| {
|
|
|
|
settings.ensure_final_newline_on_save.clone()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-23 20:52:00 +00:00
|
|
|
pub fn format_on_save(&self, language: Option<&str>) -> FormatOnSave {
|
|
|
|
self.language_setting(language, |settings| settings.format_on_save.clone())
|
2022-09-22 22:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn formatter(&self, language: Option<&str>) -> Formatter {
|
|
|
|
self.language_setting(language, |settings| settings.formatter.clone())
|
2022-04-28 21:31:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 08:07:31 +00:00
|
|
|
pub fn enable_language_server(&self, language: Option<&str>) -> bool {
|
2022-06-23 14:40:57 +00:00
|
|
|
self.language_setting(language, |settings| settings.enable_language_server)
|
|
|
|
}
|
|
|
|
|
2022-07-12 18:35:19 +00:00
|
|
|
fn language_setting<F, R>(&self, language: Option<&str>, f: F) -> R
|
2022-06-23 14:40:57 +00:00
|
|
|
where
|
2022-07-12 18:42:43 +00:00
|
|
|
F: Fn(&EditorSettings) -> Option<R>,
|
2022-06-23 14:40:57 +00:00
|
|
|
{
|
2022-07-12 18:35:19 +00:00
|
|
|
None.or_else(|| language.and_then(|l| self.language_overrides.get(l).and_then(&f)))
|
|
|
|
.or_else(|| f(&self.editor_overrides))
|
|
|
|
.or_else(|| language.and_then(|l| self.language_defaults.get(l).and_then(&f)))
|
|
|
|
.or_else(|| f(&self.editor_defaults))
|
|
|
|
.expect("missing default")
|
2022-06-09 08:07:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-03 19:42:30 +00:00
|
|
|
pub fn git_gutter(&self) -> GitGutter {
|
|
|
|
self.git_overrides.git_gutter.unwrap_or_else(|| {
|
|
|
|
self.git
|
|
|
|
.git_gutter
|
|
|
|
.expect("git_gutter should be some by setting setup")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:49:54 +00:00
|
|
|
pub fn telemetry(&self) -> TelemetrySettings {
|
|
|
|
TelemetrySettings {
|
|
|
|
diagnostics: Some(self.telemetry_diagnostics()),
|
|
|
|
metrics: Some(self.telemetry_metrics()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:06:48 +00:00
|
|
|
pub fn telemetry_diagnostics(&self) -> bool {
|
|
|
|
self.telemetry_overrides
|
|
|
|
.diagnostics
|
|
|
|
.or(self.telemetry_defaults.diagnostics)
|
|
|
|
.expect("missing default")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn telemetry_metrics(&self) -> bool {
|
|
|
|
self.telemetry_overrides
|
|
|
|
.metrics
|
|
|
|
.or(self.telemetry_defaults.metrics)
|
|
|
|
.expect("missing default")
|
|
|
|
}
|
|
|
|
|
2023-04-21 00:24:27 +00:00
|
|
|
fn terminal_setting<F, R>(&self, f: F) -> R
|
|
|
|
where
|
|
|
|
F: Fn(&TerminalSettings) -> Option<R>,
|
|
|
|
{
|
|
|
|
None.or_else(|| f(&self.terminal_overrides))
|
|
|
|
.or_else(|| f(&self.terminal_defaults))
|
|
|
|
.expect("missing default")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn terminal_line_height(&self) -> f32 {
|
|
|
|
self.terminal_setting(|terminal_setting| terminal_setting.line_height())
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:18:24 +00:00
|
|
|
pub fn terminal_scroll(&self) -> AlternateScroll {
|
2023-04-21 00:24:27 +00:00
|
|
|
self.terminal_setting(|terminal_setting| terminal_setting.alternate_scroll.to_owned())
|
2022-12-08 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 00:10:22 +00:00
|
|
|
pub fn terminal_shell(&self) -> Shell {
|
2023-04-21 00:24:27 +00:00
|
|
|
self.terminal_setting(|terminal_setting| terminal_setting.shell.to_owned())
|
2022-12-08 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn terminal_env(&self) -> HashMap<String, String> {
|
2023-04-21 00:24:27 +00:00
|
|
|
self.terminal_setting(|terminal_setting| terminal_setting.env.to_owned())
|
2022-12-09 00:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn terminal_strategy(&self) -> WorkingDirectory {
|
2023-04-21 00:24:27 +00:00
|
|
|
self.terminal_setting(|terminal_setting| terminal_setting.working_directory.to_owned())
|
2022-12-08 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 00:10:17 +00:00
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
|
|
pub fn test(cx: &gpui::AppContext) -> Settings {
|
|
|
|
Settings {
|
2023-03-17 08:51:07 +00:00
|
|
|
buffer_font_family_name: "Monaco".to_string(),
|
|
|
|
buffer_font_features: Default::default(),
|
|
|
|
buffer_font_family: cx
|
|
|
|
.font_cache()
|
2023-03-17 12:54:56 +00:00
|
|
|
.load_family(&["Monaco"], &Default::default())
|
2023-03-17 08:51:07 +00:00
|
|
|
.unwrap(),
|
2022-04-06 00:10:17 +00:00
|
|
|
buffer_font_size: 14.,
|
2022-10-26 00:24:19 +00:00
|
|
|
active_pane_magnification: 1.,
|
2022-05-27 20:02:52 +00:00
|
|
|
default_buffer_font_size: 14.,
|
2023-01-20 21:02:38 +00:00
|
|
|
confirm_quit: false,
|
2022-10-17 23:19:03 +00:00
|
|
|
cursor_blink: true,
|
2022-06-27 23:21:22 +00:00
|
|
|
hover_popover_enabled: true,
|
2022-07-12 20:09:01 +00:00
|
|
|
show_completions_on_input: true,
|
2023-01-31 23:17:16 +00:00
|
|
|
show_call_status_icon: true,
|
2022-04-06 00:10:17 +00:00
|
|
|
vim_mode: false,
|
2022-07-05 11:01:27 +00:00
|
|
|
autosave: Autosave::Off,
|
2022-09-09 02:32:38 +00:00
|
|
|
default_dock_anchor: DockAnchor::Bottom,
|
2022-07-12 18:42:43 +00:00
|
|
|
editor_defaults: EditorSettings {
|
2022-07-12 18:35:19 +00:00
|
|
|
tab_size: Some(4.try_into().unwrap()),
|
|
|
|
hard_tabs: Some(false),
|
|
|
|
soft_wrap: Some(SoftWrap::None),
|
|
|
|
preferred_line_length: Some(80),
|
2023-02-27 20:14:18 +00:00
|
|
|
remove_trailing_whitespace_on_save: Some(true),
|
2023-02-27 22:32:08 +00:00
|
|
|
ensure_final_newline_on_save: Some(true),
|
2022-09-23 20:52:00 +00:00
|
|
|
format_on_save: Some(FormatOnSave::On),
|
2022-09-22 22:21:05 +00:00
|
|
|
formatter: Some(Formatter::LanguageServer),
|
2022-07-12 18:35:19 +00:00
|
|
|
enable_language_server: Some(true),
|
2023-04-19 18:07:05 +00:00
|
|
|
show_copilot_suggestions: Some(true),
|
2023-05-05 11:30:16 +00:00
|
|
|
show_whitespaces: Some(ShowWhitespaces::None),
|
2022-07-12 18:35:19 +00:00
|
|
|
},
|
|
|
|
editor_overrides: Default::default(),
|
2023-04-28 01:06:52 +00:00
|
|
|
copilot: Default::default(),
|
2022-09-28 20:25:37 +00:00
|
|
|
journal_defaults: Default::default(),
|
|
|
|
journal_overrides: Default::default(),
|
2022-07-16 01:27:10 +00:00
|
|
|
terminal_defaults: Default::default(),
|
|
|
|
terminal_overrides: Default::default(),
|
2022-10-04 00:43:05 +00:00
|
|
|
git: Default::default(),
|
2022-10-03 19:42:30 +00:00
|
|
|
git_overrides: Default::default(),
|
2022-06-23 14:40:57 +00:00
|
|
|
language_defaults: Default::default(),
|
2022-04-06 00:10:17 +00:00
|
|
|
language_overrides: Default::default(),
|
2022-08-04 02:32:18 +00:00
|
|
|
lsp: Default::default(),
|
2022-08-10 21:39:24 +00:00
|
|
|
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), Default::default),
|
2023-01-11 00:38:07 +00:00
|
|
|
telemetry_defaults: TelemetrySettings {
|
|
|
|
diagnostics: Some(true),
|
|
|
|
metrics: Some(true),
|
|
|
|
},
|
2023-01-10 23:06:48 +00:00
|
|
|
telemetry_overrides: Default::default(),
|
2023-02-15 02:05:42 +00:00
|
|
|
auto_update: true,
|
2023-03-08 01:13:01 +00:00
|
|
|
base_keymap: Default::default(),
|
2023-04-19 18:07:05 +00:00
|
|
|
features: Features { copilot: true },
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 23:03:00 +00:00
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
|
|
pub fn test_async(cx: &mut gpui::TestAppContext) {
|
|
|
|
cx.update(|cx| {
|
|
|
|
let settings = Self::test(cx);
|
2022-08-10 21:39:24 +00:00
|
|
|
cx.set_global(settings);
|
2022-05-23 23:03:00 +00:00
|
|
|
});
|
|
|
|
}
|
2022-04-06 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 00:43:34 +00:00
|
|
|
fn merge<T: Copy>(target: &mut T, value: Option<T>) {
|
|
|
|
if let Some(value) = value {
|
|
|
|
*target = value;
|
|
|
|
}
|
|
|
|
}
|