From 81a8e1a0fe131956fcea36d442bae0f9476d81cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20F=C3=B6rster?= Date: Tue, 12 Sep 2023 09:29:20 +0200 Subject: [PATCH] Allow passing additional arguments to ChkTeX See #927. --- CHANGELOG.md | 6 ++++++ crates/base-db/src/config.rs | 2 ++ crates/texlab/src/server/options.rs | 3 +++ crates/texlab/src/util/chktex.rs | 17 +++++++++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9009b272..cef44192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Allow passing additional arguments to `ChkTeX` using `texlab.chktex.additionalArgs` ([#927](https://github.com/latex-lsp/texlab/issues/927)) + ## [5.9.2] - 2023-08-14 ### Fixed diff --git a/crates/base-db/src/config.rs b/crates/base-db/src/config.rs index bffd28b9..65728e08 100644 --- a/crates/base-db/src/config.rs +++ b/crates/base-db/src/config.rs @@ -41,6 +41,7 @@ pub struct ChktexConfig { pub on_open: bool, pub on_save: bool, pub on_edit: bool, + pub additional_args: Vec, } #[derive(Debug)] @@ -139,6 +140,7 @@ impl Default for ChktexConfig { on_open: false, on_save: false, on_edit: false, + additional_args: Vec::new(), } } } diff --git a/crates/texlab/src/server/options.rs b/crates/texlab/src/server/options.rs index 30eff447..3a2bf1bb 100644 --- a/crates/texlab/src/server/options.rs +++ b/crates/texlab/src/server/options.rs @@ -81,6 +81,7 @@ pub struct BuildOptions { pub struct ChktexOptions { pub on_open_and_save: bool, pub on_edit: bool, + pub additional_args: Option>, } #[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] @@ -199,6 +200,8 @@ impl From for Config { config.diagnostics.chktex.on_open = value.chktex.on_open_and_save; config.diagnostics.chktex.on_save = value.chktex.on_open_and_save; config.diagnostics.chktex.on_edit = value.chktex.on_edit; + config.diagnostics.chktex.additional_args = + value.chktex.additional_args.unwrap_or_default(); config.formatting.tex_formatter = match value.latex_formatter { LatexFormatter::None => Formatter::Null, diff --git a/crates/texlab/src/util/chktex.rs b/crates/texlab/src/util/chktex.rs index 91d74a9c..61661087 100644 --- a/crates/texlab/src/util/chktex.rs +++ b/crates/texlab/src/util/chktex.rs @@ -16,6 +16,7 @@ use regex::Regex; pub struct Command { text: String, working_dir: PathBuf, + additional_args: Vec, } impl Command { @@ -39,13 +40,21 @@ impl Command { log::debug!("Calling ChkTeX from directory: {}", working_dir.display()); let text = document.text.clone(); - - Some(Self { text, working_dir }) + let config = &workspace.config().diagnostics.chktex; + let additional_args = config.additional_args.clone(); + Some(Self { + text, + working_dir, + additional_args, + }) } - pub fn run(self) -> std::io::Result> { + pub fn run(mut self) -> std::io::Result> { + let mut args = vec!["-I0".into(), "-f%l:%c:%d:%k:%n:%m\n".into()]; + args.append(&mut self.additional_args); + let mut child = std::process::Command::new("chktex") - .args(["-I0", "-f%l:%c:%d:%k:%n:%m\n"]) + .args(args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::null())