Backward compat format settings
This commit is contained in:
parent
af5ad2d5ce
commit
879a0d8b12
3 changed files with 26 additions and 12 deletions
|
@ -43,7 +43,7 @@
|
||||||
// "default_dock_anchor": "expanded"
|
// "default_dock_anchor": "expanded"
|
||||||
"default_dock_anchor": "right",
|
"default_dock_anchor": "right",
|
||||||
// Whether or not to perform a buffer format before saving
|
// Whether or not to perform a buffer format before saving
|
||||||
"format_on_save": true,
|
"format_on_save": "off",
|
||||||
// How to perform a buffer format. This setting can take two values:
|
// How to perform a buffer format. This setting can take two values:
|
||||||
//
|
//
|
||||||
// 1. Format code using the current language server:
|
// 1. Format code using the current language server:
|
||||||
|
|
|
@ -40,7 +40,7 @@ use postage::watch;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use search::SearchQuery;
|
use search::SearchQuery;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use settings::Settings;
|
use settings::{FormatOnSave, Formatter, Settings};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use similar::{ChangeTag, TextDiff};
|
use similar::{ChangeTag, TextDiff};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -3120,12 +3120,11 @@ impl Project {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
if trigger == FormatTrigger::Save && !format_on_save {
|
let transaction = match (formatter, format_on_save) {
|
||||||
continue;
|
(_, FormatOnSave::Off) if trigger == FormatTrigger::Save => continue,
|
||||||
}
|
|
||||||
|
|
||||||
let transaction = match formatter {
|
(Formatter::LanguageServer, FormatOnSave::On | FormatOnSave::Off)
|
||||||
settings::Formatter::LanguageServer => Self::format_via_lsp(
|
| (_, FormatOnSave::LanguageServer) => Self::format_via_lsp(
|
||||||
&this,
|
&this,
|
||||||
&buffer,
|
&buffer,
|
||||||
&buffer_abs_path,
|
&buffer_abs_path,
|
||||||
|
@ -3136,7 +3135,11 @@ impl Project {
|
||||||
.await
|
.await
|
||||||
.context("failed to format via language server")?,
|
.context("failed to format via language server")?,
|
||||||
|
|
||||||
settings::Formatter::External { command, arguments } => {
|
(
|
||||||
|
Formatter::External { command, arguments },
|
||||||
|
FormatOnSave::On | FormatOnSave::Off,
|
||||||
|
)
|
||||||
|
| (_, FormatOnSave::External { command, arguments }) => {
|
||||||
Self::format_via_external_command(
|
Self::format_via_external_command(
|
||||||
&buffer,
|
&buffer,
|
||||||
&buffer_abs_path,
|
&buffer_abs_path,
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub struct EditorSettings {
|
||||||
pub hard_tabs: Option<bool>,
|
pub hard_tabs: Option<bool>,
|
||||||
pub soft_wrap: Option<SoftWrap>,
|
pub soft_wrap: Option<SoftWrap>,
|
||||||
pub preferred_line_length: Option<u32>,
|
pub preferred_line_length: Option<u32>,
|
||||||
pub format_on_save: Option<bool>,
|
pub format_on_save: Option<FormatOnSave>,
|
||||||
pub formatter: Option<Formatter>,
|
pub formatter: Option<Formatter>,
|
||||||
pub enable_language_server: Option<bool>,
|
pub enable_language_server: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,17 @@ pub enum SoftWrap {
|
||||||
EditorWidth,
|
EditorWidth,
|
||||||
PreferredLineLength,
|
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)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
|
@ -324,8 +335,8 @@ impl Settings {
|
||||||
self.language_setting(language, |settings| settings.preferred_line_length)
|
self.language_setting(language, |settings| settings.preferred_line_length)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_on_save(&self, language: Option<&str>) -> bool {
|
pub fn format_on_save(&self, language: Option<&str>) -> FormatOnSave {
|
||||||
self.language_setting(language, |settings| settings.format_on_save)
|
self.language_setting(language, |settings| settings.format_on_save.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn formatter(&self, language: Option<&str>) -> Formatter {
|
pub fn formatter(&self, language: Option<&str>) -> Formatter {
|
||||||
|
@ -364,7 +375,7 @@ impl Settings {
|
||||||
hard_tabs: Some(false),
|
hard_tabs: Some(false),
|
||||||
soft_wrap: Some(SoftWrap::None),
|
soft_wrap: Some(SoftWrap::None),
|
||||||
preferred_line_length: Some(80),
|
preferred_line_length: Some(80),
|
||||||
format_on_save: Some(true),
|
format_on_save: Some(FormatOnSave::On),
|
||||||
formatter: Some(Formatter::LanguageServer),
|
formatter: Some(Formatter::LanguageServer),
|
||||||
enable_language_server: Some(true),
|
enable_language_server: Some(true),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue