Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing additional arguments to ChkTeX #928

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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