From 410adf5520f1f4e2b1ece31942694a14d0ed4e7c Mon Sep 17 00:00:00 2001 From: Nolan Date: Sat, 19 Oct 2024 04:18:08 -0400 Subject: [PATCH] Add latexindent replacement options (#1241) Add an option field "replacement" to the LatexIndentConfig structs, and modify the build_arguments function to check if it config.replacement contains one of "-r", "-rr", or "-rv". If so, it appends that to the list of arguments to LatexIndent. If it does not exist, or it contains any other string, the option is ignored. --- crates/base-db/src/config.rs | 1 + crates/texlab/src/features/formatting/latexindent.rs | 9 +++++++++ crates/texlab/src/server/options.rs | 1 + crates/texlab/src/util/from_proto.rs | 1 + 4 files changed, 12 insertions(+) diff --git a/crates/base-db/src/config.rs b/crates/base-db/src/config.rs index 455fdc2a6..5774f2a0e 100644 --- a/crates/base-db/src/config.rs +++ b/crates/base-db/src/config.rs @@ -68,6 +68,7 @@ pub enum Formatter { pub struct LatexIndentConfig { pub local: Option, pub modify_line_breaks: bool, + pub replacement: Option, } #[derive(Debug, Default)] diff --git a/crates/texlab/src/features/formatting/latexindent.rs b/crates/texlab/src/features/formatting/latexindent.rs index d3fffc205..e1a277c0c 100644 --- a/crates/texlab/src/features/formatting/latexindent.rs +++ b/crates/texlab/src/features/formatting/latexindent.rs @@ -72,6 +72,15 @@ fn build_arguments(config: &LatexIndentConfig, target_file: &Path) -> Vec { + if ["-r", "-rv", "-rr"].contains(& replacement_flag.as_str()) { + args.push(replacement_flag.clone()); + } + }, + None => {} + } + args.push(target_file.display().to_string()); args } diff --git a/crates/texlab/src/server/options.rs b/crates/texlab/src/server/options.rs index bc785c56c..fcb8e1ec6 100644 --- a/crates/texlab/src/server/options.rs +++ b/crates/texlab/src/server/options.rs @@ -56,6 +56,7 @@ impl Default for LatexFormatter { pub struct LatexindentOptions { pub local: Option, pub modify_line_breaks: bool, + pub replacement: Option, } #[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] diff --git a/crates/texlab/src/util/from_proto.rs b/crates/texlab/src/util/from_proto.rs index 2f4fbe64c..928b3d6d6 100644 --- a/crates/texlab/src/util/from_proto.rs +++ b/crates/texlab/src/util/from_proto.rs @@ -282,6 +282,7 @@ pub fn config(value: Options) -> Config { config.formatting.latex_indent.local = value.latexindent.local; config.formatting.latex_indent.modify_line_breaks = value.latexindent.modify_line_breaks; + config.formatting.latex_indent.replacement = value.latexindent.replacement; config.synctex = value .forward_search