diff options
author | Norbert Preining <norbert@preining.info> | 2020-05-28 03:03:21 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-05-28 03:03:21 +0000 |
commit | 745892fbddea56040139108277e728b53fd8fc11 (patch) | |
tree | 15e55e299b38fccdabce8364f1fbf4f02ef37994 /support/texlab/src/protocol/options.rs | |
parent | 195ca7e0c377d83455867bdd8e409d4e1cf024ea (diff) |
CTAN sync 202005280303
Diffstat (limited to 'support/texlab/src/protocol/options.rs')
-rw-r--r-- | support/texlab/src/protocol/options.rs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/support/texlab/src/protocol/options.rs b/support/texlab/src/protocol/options.rs new file mode 100644 index 0000000000..86718d1e72 --- /dev/null +++ b/support/texlab/src/protocol/options.rs @@ -0,0 +1,104 @@ +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum BibtexFormatter { + Texlab, + Latexindent, +} + +impl Default for BibtexFormatter { + fn default() -> Self { + Self::Texlab + } +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BibtexFormattingOptions { + pub line_length: Option<i32>, + pub formatter: Option<BibtexFormatter>, +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +pub struct LatexForwardSearchOptions { + pub executable: Option<String>, + pub args: Option<Vec<String>>, +} + +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct LatexLintOptions { + pub on_change: Option<bool>, + pub on_save: Option<bool>, +} + +impl LatexLintOptions { + pub fn on_change(&self) -> bool { + self.on_change.unwrap_or(false) + } + + pub fn on_save(&self) -> bool { + self.on_save.unwrap_or(false) + } +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct LatexBuildOptions { + pub executable: Option<String>, + pub args: Option<Vec<String>>, + pub on_save: Option<bool>, + pub output_directory: Option<PathBuf>, + pub forward_search_after: Option<bool>, +} + +impl LatexBuildOptions { + pub fn executable(&self) -> String { + self.executable + .as_ref() + .map(Clone::clone) + .unwrap_or_else(|| "latexmk".to_owned()) + } + + pub fn args(&self) -> Vec<String> { + self.args.as_ref().map(Clone::clone).unwrap_or_else(|| { + vec![ + "-pdf".to_owned(), + "-interaction=nonstopmode".to_owned(), + "-synctex=1".to_owned(), + ] + }) + } + + pub fn on_save(&self) -> bool { + self.on_save.unwrap_or(false) + } + + pub fn forward_search_after(&self) -> bool { + self.forward_search_after.unwrap_or(false) + } +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct LatexOptions { + pub forward_search: Option<LatexForwardSearchOptions>, + pub lint: Option<LatexLintOptions>, + pub build: Option<LatexBuildOptions>, + pub root_directory: Option<PathBuf>, +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BibtexOptions { + pub formatting: Option<BibtexFormattingOptions>, +} + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Options { + pub latex: Option<LatexOptions>, + pub bibtex: Option<BibtexOptions>, +} |