Rename LanguageSettings -> EditorSettings

This commit is contained in:
Max Brunsfeld 2022-07-12 11:42:43 -07:00
parent ec8a493700
commit c02f4ea8dc
5 changed files with 32 additions and 29 deletions

View file

@ -2,17 +2,17 @@
"theme": "cave-dark",
"buffer_font_family": "Zed Mono",
"buffer_font_size": 15,
"hover_popover_enabled": true,
"vim_mode": false,
"autosave": "off",
"hover_popover_enabled": true,
"projects_online_by_default": true,
"enable_language_server": true,
"autosave": "off",
"format_on_save": "language_server",
"preferred_line_length": 80,
"soft_wrap": "none",
"hard_tabs": false,
"tab_size": 4,
"languages_overrides": {
"languages": {
"Plain Text": {
"soft_wrap": "preferred_line_length"
},

View file

@ -6236,7 +6236,7 @@ mod tests {
use language::{FakeLspAdapter, LanguageConfig};
use lsp::FakeLanguageServer;
use project::FakeFs;
use settings::LanguageSettings;
use settings::EditorSettings;
use std::{cell::RefCell, rc::Rc, time::Instant};
use text::Point;
use unindent::Unindent;
@ -7696,14 +7696,14 @@ mod tests {
Settings::test(cx)
.with_language_defaults(
"TOML",
LanguageSettings {
EditorSettings {
tab_size: Some(2.try_into().unwrap()),
..Default::default()
},
)
.with_language_defaults(
"Rust",
LanguageSettings {
EditorSettings {
tab_size: Some(4.try_into().unwrap()),
..Default::default()
},
@ -9380,7 +9380,7 @@ mod tests {
cx.update_global::<Settings, _, _>(|settings, _| {
settings.language_overrides.insert(
"Rust".into(),
LanguageSettings {
EditorSettings {
tab_size: Some(8.try_into().unwrap()),
..Default::default()
},
@ -9496,7 +9496,7 @@ mod tests {
cx.update_global::<Settings, _, _>(|settings, _| {
settings.language_overrides.insert(
"Rust".into(),
LanguageSettings {
EditorSettings {
tab_size: Some(8.try_into().unwrap()),
..Default::default()
},

View file

@ -883,7 +883,7 @@ async fn test_toggling_enable_language_server(
cx.update_global(|settings: &mut Settings, _| {
settings.language_overrides.insert(
Arc::from("Rust"),
settings::LanguageSettings {
settings::EditorSettings {
enable_language_server: Some(false),
..Default::default()
},
@ -900,14 +900,14 @@ async fn test_toggling_enable_language_server(
cx.update_global(|settings: &mut Settings, _| {
settings.language_overrides.insert(
Arc::from("Rust"),
settings::LanguageSettings {
settings::EditorSettings {
enable_language_server: Some(true),
..Default::default()
},
);
settings.language_overrides.insert(
Arc::from("JavaScript"),
settings::LanguageSettings {
settings::EditorSettings {
enable_language_server: Some(false),
..Default::default()
},

View file

@ -14,7 +14,7 @@ use schemars::{
};
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value;
use std::{collections::HashMap, num::NonZeroU32, sync::Arc};
use std::{collections::HashMap, num::NonZeroU32, str, sync::Arc};
use theme::{Theme, ThemeRegistry};
use util::ResultExt as _;
@ -29,15 +29,15 @@ pub struct Settings {
pub hover_popover_enabled: bool,
pub vim_mode: bool,
pub autosave: Autosave,
pub editor_defaults: LanguageSettings,
pub editor_overrides: LanguageSettings,
pub language_defaults: HashMap<Arc<str>, LanguageSettings>,
pub language_overrides: HashMap<Arc<str>, LanguageSettings>,
pub editor_defaults: EditorSettings,
pub editor_overrides: EditorSettings,
pub language_defaults: HashMap<Arc<str>, EditorSettings>,
pub language_overrides: HashMap<Arc<str>, EditorSettings>,
pub theme: Arc<Theme>,
}
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
pub struct LanguageSettings {
pub struct EditorSettings {
pub tab_size: Option<NonZeroU32>,
pub hard_tabs: Option<bool>,
pub soft_wrap: Option<SoftWrap>,
@ -89,9 +89,10 @@ pub struct SettingsFileContent {
#[serde(default)]
pub autosave: Option<Autosave>,
#[serde(flatten)]
pub editor: LanguageSettings,
pub editor: EditorSettings,
#[serde(default)]
pub language_overrides: HashMap<Arc<str>, LanguageSettings>,
#[serde(alias = "language_overrides")]
pub languages: HashMap<Arc<str>, EditorSettings>,
#[serde(default)]
pub theme: Option<String>,
}
@ -107,8 +108,10 @@ impl Settings {
value
}
let defaults: SettingsFileContent =
serde_json::from_slice(assets.load("default-settings.json").unwrap().as_ref()).unwrap();
let defaults: SettingsFileContent = parse_json_with_comments(
str::from_utf8(assets.load("default-settings.json").unwrap().as_ref()).unwrap(),
)
.unwrap();
Self {
buffer_font_family: font_cache
@ -120,7 +123,7 @@ impl Settings {
projects_online_by_default: defaults.projects_online_by_default.unwrap(),
vim_mode: defaults.vim_mode.unwrap(),
autosave: defaults.autosave.unwrap(),
editor_defaults: LanguageSettings {
editor_defaults: EditorSettings {
tab_size: required(defaults.editor.tab_size),
hard_tabs: required(defaults.editor.hard_tabs),
soft_wrap: required(defaults.editor.soft_wrap),
@ -128,7 +131,7 @@ impl Settings {
format_on_save: required(defaults.editor.format_on_save),
enable_language_server: required(defaults.editor.enable_language_server),
},
language_defaults: defaults.language_overrides,
language_defaults: defaults.languages,
editor_overrides: Default::default(),
language_overrides: Default::default(),
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
@ -138,7 +141,7 @@ impl Settings {
pub fn with_language_defaults(
mut self,
language_name: impl Into<Arc<str>>,
overrides: LanguageSettings,
overrides: EditorSettings,
) -> Self {
self.language_defaults
.insert(language_name.into(), overrides);
@ -171,7 +174,7 @@ impl Settings {
fn language_setting<F, R>(&self, language: Option<&str>, f: F) -> R
where
F: Fn(&LanguageSettings) -> Option<R>,
F: Fn(&EditorSettings) -> Option<R>,
{
None.or_else(|| language.and_then(|l| self.language_overrides.get(l).and_then(&f)))
.or_else(|| f(&self.editor_overrides))
@ -189,7 +192,7 @@ impl Settings {
hover_popover_enabled: true,
vim_mode: false,
autosave: Autosave::Off,
editor_defaults: LanguageSettings {
editor_defaults: EditorSettings {
tab_size: Some(4.try_into().unwrap()),
hard_tabs: Some(false),
soft_wrap: Some(SoftWrap::None),
@ -255,7 +258,7 @@ impl Settings {
data.editor.preferred_line_length,
);
for (language_name, settings) in data.language_overrides.clone().into_iter() {
for (language_name, settings) in data.languages.clone().into_iter() {
let target = self
.language_overrides
.entry(language_name.into())

View file

@ -93,7 +93,7 @@ pub async fn watch_keymap_file(
mod tests {
use super::*;
use project::FakeFs;
use settings::{LanguageSettings, SoftWrap};
use settings::{EditorSettings, SoftWrap};
#[gpui::test]
async fn test_settings_from_files(cx: &mut gpui::TestAppContext) {
@ -128,7 +128,7 @@ mod tests {
let settings = cx.read(Settings::test).with_language_defaults(
"JavaScript",
LanguageSettings {
EditorSettings {
tab_size: Some(2.try_into().unwrap()),
..Default::default()
},