Backward compat format settings

This commit is contained in:
Julia 2022-09-23 16:52:00 -04:00
parent af5ad2d5ce
commit 879a0d8b12
3 changed files with 26 additions and 12 deletions

View file

@ -58,7 +58,7 @@ pub struct EditorSettings {
pub hard_tabs: Option<bool>,
pub soft_wrap: Option<SoftWrap>,
pub preferred_line_length: Option<u32>,
pub format_on_save: Option<bool>,
pub format_on_save: Option<FormatOnSave>,
pub formatter: Option<Formatter>,
pub enable_language_server: Option<bool>,
}
@ -70,6 +70,17 @@ pub enum SoftWrap {
EditorWidth,
PreferredLineLength,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum FormatOnSave {
On,
Off,
LanguageServer,
External {
command: String,
arguments: Vec<String>,
},
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
@ -324,8 +335,8 @@ impl Settings {
self.language_setting(language, |settings| settings.preferred_line_length)
}
pub fn format_on_save(&self, language: Option<&str>) -> bool {
self.language_setting(language, |settings| settings.format_on_save)
pub fn format_on_save(&self, language: Option<&str>) -> FormatOnSave {
self.language_setting(language, |settings| settings.format_on_save.clone())
}
pub fn formatter(&self, language: Option<&str>) -> Formatter {
@ -364,7 +375,7 @@ impl Settings {
hard_tabs: Some(false),
soft_wrap: Some(SoftWrap::None),
preferred_line_length: Some(80),
format_on_save: Some(true),
format_on_save: Some(FormatOnSave::On),
formatter: Some(Formatter::LanguageServer),
enable_language_server: Some(true),
},