Skip to content

Commit

Permalink
Allow passing additional arguments to ChkTeX (#928)
Browse files Browse the repository at this point in the history
Fixes #927.
  • Loading branch information
pfoerster authored Sep 12, 2023
1 parent b5c7e64 commit 3b305df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crates/base-db/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct ChktexConfig {
pub on_open: bool,
pub on_save: bool,
pub on_edit: bool,
pub additional_args: Vec<String>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -139,6 +140,7 @@ impl Default for ChktexConfig {
on_open: false,
on_save: false,
on_edit: false,
additional_args: Vec::new(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/texlab/src/server/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct BuildOptions {
pub struct ChktexOptions {
pub on_open_and_save: bool,
pub on_edit: bool,
pub additional_args: Option<Vec<String>>,
}

#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -199,6 +200,8 @@ impl From<Options> 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,
Expand Down
17 changes: 13 additions & 4 deletions crates/texlab/src/util/chktex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use regex::Regex;
pub struct Command {
text: String,
working_dir: PathBuf,
additional_args: Vec<String>,
}

impl Command {
Expand All @@ -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<Vec<Diagnostic>> {
pub fn run(mut self) -> std::io::Result<Vec<Diagnostic>> {
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())
Expand Down

0 comments on commit 3b305df

Please sign in to comment.