mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-08-04 10:49:55 +00:00
Add more latexindent options
This commit is contained in:
parent
5c7b0d1146
commit
20a6525477
4 changed files with 61 additions and 2 deletions
|
@ -143,3 +143,27 @@ Possible values are either `texlab` or `latexindent`.
|
|||
**Type:** `string`
|
||||
|
||||
**Default value:** `texlab`
|
||||
|
||||
---
|
||||
|
||||
## texlab.latexFormatter
|
||||
|
||||
Defines the formatter to use for LaTeX formatting.
|
||||
Possible values are either `texlab` or `latexindent`.
|
||||
Note that `texlab` is not implemented yet.
|
||||
|
||||
**Type:** `string`
|
||||
|
||||
**Default value:** `latexindent`
|
||||
|
||||
---
|
||||
|
||||
## texlab.latexindent.local
|
||||
|
||||
Defines the path of a file containing the `latexindent` configuration.
|
||||
This corresponds to the `--local=file.yaml` flag of `latexindent`.
|
||||
By default the configuration inside the project root directory is used.
|
||||
|
||||
**Type:** `string`
|
||||
|
||||
**Default value:** `null`
|
||||
|
|
|
@ -4,7 +4,7 @@ mod latexindent;
|
|||
use cancellation::CancellationToken;
|
||||
use lsp_types::{DocumentFormattingParams, TextEdit};
|
||||
|
||||
use crate::BibtexFormatter;
|
||||
use crate::{BibtexFormatter, LatexFormatter};
|
||||
|
||||
use self::{bibtex_internal::format_bibtex_internal, latexindent::format_with_latexindent};
|
||||
|
||||
|
@ -19,6 +19,10 @@ pub fn format_source_code(
|
|||
edits = edits.or_else(|| format_bibtex_internal(&request, cancellation_token));
|
||||
}
|
||||
|
||||
if request.context.options.read().unwrap().latex_formatter == LatexFormatter::Texlab {
|
||||
edits = edits.or_else(|| Some(vec![]));
|
||||
}
|
||||
|
||||
edits = edits.or_else(|| format_with_latexindent(&request, cancellation_token));
|
||||
edits
|
||||
}
|
||||
|
|
|
@ -35,6 +35,12 @@ pub fn format_with_latexindent(
|
|||
}
|
||||
})
|
||||
.unwrap_or_else(|| ".".into());
|
||||
|
||||
let local = match &options.latexindent.local {
|
||||
Some(local) => format!("--local={}", local),
|
||||
None => "-l".to_string(),
|
||||
};
|
||||
|
||||
drop(options);
|
||||
|
||||
let path = directory.path();
|
||||
|
@ -60,7 +66,7 @@ pub fn format_with_latexindent(
|
|||
fs::write(directory.path().join(name), &document.text).ok()?;
|
||||
|
||||
let output = Command::new("latexindent")
|
||||
.args(&["-l", name])
|
||||
.args(&[&local, name])
|
||||
.current_dir(current_dir)
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
|
|
|
@ -12,6 +12,9 @@ pub struct Options {
|
|||
#[serde(default)]
|
||||
pub bibtex_formatter: BibtexFormatter,
|
||||
|
||||
#[serde(default)]
|
||||
pub latex_formatter: LatexFormatter,
|
||||
|
||||
pub formatter_line_length: Option<i32>,
|
||||
|
||||
pub diagnostics_delay: Option<u64>,
|
||||
|
@ -22,6 +25,9 @@ pub struct Options {
|
|||
#[serde(default)]
|
||||
pub chktex: ChktexOptions,
|
||||
|
||||
#[serde(default)]
|
||||
pub latexindent: LatexindentOptions,
|
||||
|
||||
pub forward_search: Option<ForwardSearchOptions>,
|
||||
}
|
||||
|
||||
|
@ -38,6 +44,25 @@ impl Default for BibtexFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum LatexFormatter {
|
||||
Texlab,
|
||||
Latexindent,
|
||||
}
|
||||
|
||||
impl Default for LatexFormatter {
|
||||
fn default() -> Self {
|
||||
Self::Latexindent
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LatexindentOptions {
|
||||
pub local: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BuildOptions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue