mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Rename LanguageSettings -> EditorSettings
This commit is contained in:
parent
ec8a493700
commit
c02f4ea8dc
5 changed files with 32 additions and 29 deletions
|
@ -2,17 +2,17 @@
|
||||||
"theme": "cave-dark",
|
"theme": "cave-dark",
|
||||||
"buffer_font_family": "Zed Mono",
|
"buffer_font_family": "Zed Mono",
|
||||||
"buffer_font_size": 15,
|
"buffer_font_size": 15,
|
||||||
"hover_popover_enabled": true,
|
|
||||||
"vim_mode": false,
|
"vim_mode": false,
|
||||||
"autosave": "off",
|
"hover_popover_enabled": true,
|
||||||
"projects_online_by_default": true,
|
"projects_online_by_default": true,
|
||||||
"enable_language_server": true,
|
"enable_language_server": true,
|
||||||
|
"autosave": "off",
|
||||||
"format_on_save": "language_server",
|
"format_on_save": "language_server",
|
||||||
"preferred_line_length": 80,
|
"preferred_line_length": 80,
|
||||||
"soft_wrap": "none",
|
"soft_wrap": "none",
|
||||||
"hard_tabs": false,
|
"hard_tabs": false,
|
||||||
"tab_size": 4,
|
"tab_size": 4,
|
||||||
"languages_overrides": {
|
"languages": {
|
||||||
"Plain Text": {
|
"Plain Text": {
|
||||||
"soft_wrap": "preferred_line_length"
|
"soft_wrap": "preferred_line_length"
|
||||||
},
|
},
|
||||||
|
|
|
@ -6236,7 +6236,7 @@ mod tests {
|
||||||
use language::{FakeLspAdapter, LanguageConfig};
|
use language::{FakeLspAdapter, LanguageConfig};
|
||||||
use lsp::FakeLanguageServer;
|
use lsp::FakeLanguageServer;
|
||||||
use project::FakeFs;
|
use project::FakeFs;
|
||||||
use settings::LanguageSettings;
|
use settings::EditorSettings;
|
||||||
use std::{cell::RefCell, rc::Rc, time::Instant};
|
use std::{cell::RefCell, rc::Rc, time::Instant};
|
||||||
use text::Point;
|
use text::Point;
|
||||||
use unindent::Unindent;
|
use unindent::Unindent;
|
||||||
|
@ -7696,14 +7696,14 @@ mod tests {
|
||||||
Settings::test(cx)
|
Settings::test(cx)
|
||||||
.with_language_defaults(
|
.with_language_defaults(
|
||||||
"TOML",
|
"TOML",
|
||||||
LanguageSettings {
|
EditorSettings {
|
||||||
tab_size: Some(2.try_into().unwrap()),
|
tab_size: Some(2.try_into().unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.with_language_defaults(
|
.with_language_defaults(
|
||||||
"Rust",
|
"Rust",
|
||||||
LanguageSettings {
|
EditorSettings {
|
||||||
tab_size: Some(4.try_into().unwrap()),
|
tab_size: Some(4.try_into().unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -9380,7 +9380,7 @@ mod tests {
|
||||||
cx.update_global::<Settings, _, _>(|settings, _| {
|
cx.update_global::<Settings, _, _>(|settings, _| {
|
||||||
settings.language_overrides.insert(
|
settings.language_overrides.insert(
|
||||||
"Rust".into(),
|
"Rust".into(),
|
||||||
LanguageSettings {
|
EditorSettings {
|
||||||
tab_size: Some(8.try_into().unwrap()),
|
tab_size: Some(8.try_into().unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -9496,7 +9496,7 @@ mod tests {
|
||||||
cx.update_global::<Settings, _, _>(|settings, _| {
|
cx.update_global::<Settings, _, _>(|settings, _| {
|
||||||
settings.language_overrides.insert(
|
settings.language_overrides.insert(
|
||||||
"Rust".into(),
|
"Rust".into(),
|
||||||
LanguageSettings {
|
EditorSettings {
|
||||||
tab_size: Some(8.try_into().unwrap()),
|
tab_size: Some(8.try_into().unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -883,7 +883,7 @@ async fn test_toggling_enable_language_server(
|
||||||
cx.update_global(|settings: &mut Settings, _| {
|
cx.update_global(|settings: &mut Settings, _| {
|
||||||
settings.language_overrides.insert(
|
settings.language_overrides.insert(
|
||||||
Arc::from("Rust"),
|
Arc::from("Rust"),
|
||||||
settings::LanguageSettings {
|
settings::EditorSettings {
|
||||||
enable_language_server: Some(false),
|
enable_language_server: Some(false),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -900,14 +900,14 @@ async fn test_toggling_enable_language_server(
|
||||||
cx.update_global(|settings: &mut Settings, _| {
|
cx.update_global(|settings: &mut Settings, _| {
|
||||||
settings.language_overrides.insert(
|
settings.language_overrides.insert(
|
||||||
Arc::from("Rust"),
|
Arc::from("Rust"),
|
||||||
settings::LanguageSettings {
|
settings::EditorSettings {
|
||||||
enable_language_server: Some(true),
|
enable_language_server: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
settings.language_overrides.insert(
|
settings.language_overrides.insert(
|
||||||
Arc::from("JavaScript"),
|
Arc::from("JavaScript"),
|
||||||
settings::LanguageSettings {
|
settings::EditorSettings {
|
||||||
enable_language_server: Some(false),
|
enable_language_server: Some(false),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,7 @@ use schemars::{
|
||||||
};
|
};
|
||||||
use serde::{de::DeserializeOwned, Deserialize};
|
use serde::{de::DeserializeOwned, Deserialize};
|
||||||
use serde_json::Value;
|
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 theme::{Theme, ThemeRegistry};
|
||||||
use util::ResultExt as _;
|
use util::ResultExt as _;
|
||||||
|
|
||||||
|
@ -29,15 +29,15 @@ pub struct Settings {
|
||||||
pub hover_popover_enabled: bool,
|
pub hover_popover_enabled: bool,
|
||||||
pub vim_mode: bool,
|
pub vim_mode: bool,
|
||||||
pub autosave: Autosave,
|
pub autosave: Autosave,
|
||||||
pub editor_defaults: LanguageSettings,
|
pub editor_defaults: EditorSettings,
|
||||||
pub editor_overrides: LanguageSettings,
|
pub editor_overrides: EditorSettings,
|
||||||
pub language_defaults: HashMap<Arc<str>, LanguageSettings>,
|
pub language_defaults: HashMap<Arc<str>, EditorSettings>,
|
||||||
pub language_overrides: HashMap<Arc<str>, LanguageSettings>,
|
pub language_overrides: HashMap<Arc<str>, EditorSettings>,
|
||||||
pub theme: Arc<Theme>,
|
pub theme: Arc<Theme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct LanguageSettings {
|
pub struct EditorSettings {
|
||||||
pub tab_size: Option<NonZeroU32>,
|
pub tab_size: Option<NonZeroU32>,
|
||||||
pub hard_tabs: Option<bool>,
|
pub hard_tabs: Option<bool>,
|
||||||
pub soft_wrap: Option<SoftWrap>,
|
pub soft_wrap: Option<SoftWrap>,
|
||||||
|
@ -89,9 +89,10 @@ pub struct SettingsFileContent {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub autosave: Option<Autosave>,
|
pub autosave: Option<Autosave>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub editor: LanguageSettings,
|
pub editor: EditorSettings,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub language_overrides: HashMap<Arc<str>, LanguageSettings>,
|
#[serde(alias = "language_overrides")]
|
||||||
|
pub languages: HashMap<Arc<str>, EditorSettings>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -107,8 +108,10 @@ impl Settings {
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
let defaults: SettingsFileContent =
|
let defaults: SettingsFileContent = parse_json_with_comments(
|
||||||
serde_json::from_slice(assets.load("default-settings.json").unwrap().as_ref()).unwrap();
|
str::from_utf8(assets.load("default-settings.json").unwrap().as_ref()).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
buffer_font_family: font_cache
|
buffer_font_family: font_cache
|
||||||
|
@ -120,7 +123,7 @@ impl Settings {
|
||||||
projects_online_by_default: defaults.projects_online_by_default.unwrap(),
|
projects_online_by_default: defaults.projects_online_by_default.unwrap(),
|
||||||
vim_mode: defaults.vim_mode.unwrap(),
|
vim_mode: defaults.vim_mode.unwrap(),
|
||||||
autosave: defaults.autosave.unwrap(),
|
autosave: defaults.autosave.unwrap(),
|
||||||
editor_defaults: LanguageSettings {
|
editor_defaults: EditorSettings {
|
||||||
tab_size: required(defaults.editor.tab_size),
|
tab_size: required(defaults.editor.tab_size),
|
||||||
hard_tabs: required(defaults.editor.hard_tabs),
|
hard_tabs: required(defaults.editor.hard_tabs),
|
||||||
soft_wrap: required(defaults.editor.soft_wrap),
|
soft_wrap: required(defaults.editor.soft_wrap),
|
||||||
|
@ -128,7 +131,7 @@ impl Settings {
|
||||||
format_on_save: required(defaults.editor.format_on_save),
|
format_on_save: required(defaults.editor.format_on_save),
|
||||||
enable_language_server: required(defaults.editor.enable_language_server),
|
enable_language_server: required(defaults.editor.enable_language_server),
|
||||||
},
|
},
|
||||||
language_defaults: defaults.language_overrides,
|
language_defaults: defaults.languages,
|
||||||
editor_overrides: Default::default(),
|
editor_overrides: Default::default(),
|
||||||
language_overrides: Default::default(),
|
language_overrides: Default::default(),
|
||||||
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
||||||
|
@ -138,7 +141,7 @@ impl Settings {
|
||||||
pub fn with_language_defaults(
|
pub fn with_language_defaults(
|
||||||
mut self,
|
mut self,
|
||||||
language_name: impl Into<Arc<str>>,
|
language_name: impl Into<Arc<str>>,
|
||||||
overrides: LanguageSettings,
|
overrides: EditorSettings,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.language_defaults
|
self.language_defaults
|
||||||
.insert(language_name.into(), overrides);
|
.insert(language_name.into(), overrides);
|
||||||
|
@ -171,7 +174,7 @@ impl Settings {
|
||||||
|
|
||||||
fn language_setting<F, R>(&self, language: Option<&str>, f: F) -> R
|
fn language_setting<F, R>(&self, language: Option<&str>, f: F) -> R
|
||||||
where
|
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)))
|
None.or_else(|| language.and_then(|l| self.language_overrides.get(l).and_then(&f)))
|
||||||
.or_else(|| f(&self.editor_overrides))
|
.or_else(|| f(&self.editor_overrides))
|
||||||
|
@ -189,7 +192,7 @@ impl Settings {
|
||||||
hover_popover_enabled: true,
|
hover_popover_enabled: true,
|
||||||
vim_mode: false,
|
vim_mode: false,
|
||||||
autosave: Autosave::Off,
|
autosave: Autosave::Off,
|
||||||
editor_defaults: LanguageSettings {
|
editor_defaults: EditorSettings {
|
||||||
tab_size: Some(4.try_into().unwrap()),
|
tab_size: Some(4.try_into().unwrap()),
|
||||||
hard_tabs: Some(false),
|
hard_tabs: Some(false),
|
||||||
soft_wrap: Some(SoftWrap::None),
|
soft_wrap: Some(SoftWrap::None),
|
||||||
|
@ -255,7 +258,7 @@ impl Settings {
|
||||||
data.editor.preferred_line_length,
|
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
|
let target = self
|
||||||
.language_overrides
|
.language_overrides
|
||||||
.entry(language_name.into())
|
.entry(language_name.into())
|
||||||
|
|
|
@ -93,7 +93,7 @@ pub async fn watch_keymap_file(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use project::FakeFs;
|
use project::FakeFs;
|
||||||
use settings::{LanguageSettings, SoftWrap};
|
use settings::{EditorSettings, SoftWrap};
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_settings_from_files(cx: &mut gpui::TestAppContext) {
|
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(
|
let settings = cx.read(Settings::test).with_language_defaults(
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
LanguageSettings {
|
EditorSettings {
|
||||||
tab_size: Some(2.try_into().unwrap()),
|
tab_size: Some(2.try_into().unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue