diff options
author | Norbert Preining <norbert@preining.info> | 2021-05-23 03:00:39 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-05-23 03:00:39 +0000 |
commit | f1261b349e875b842745b63258c3e338cb1fe3bf (patch) | |
tree | b5d402b3e80818cde2c079a42249f3dcb9732247 /support/texlab/src/language.rs | |
parent | 58aa1ac09b1d9e4769d0a0661cf12e2b2db41b14 (diff) |
CTAN sync 202105230300
Diffstat (limited to 'support/texlab/src/language.rs')
-rw-r--r-- | support/texlab/src/language.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/support/texlab/src/language.rs b/support/texlab/src/language.rs new file mode 100644 index 0000000000..45ef22daba --- /dev/null +++ b/support/texlab/src/language.rs @@ -0,0 +1,33 @@ +use std::{ffi::OsStr, path::Path}; + +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, PartialOrd, Ord)] +pub enum DocumentLanguage { + Latex, + Bibtex, + BuildLog, +} + +impl DocumentLanguage { + pub fn by_path(path: &Path) -> Option<Self> { + path.extension() + .and_then(OsStr::to_str) + .and_then(Self::by_extension) + } + + pub fn by_extension(extension: &str) -> Option<Self> { + match extension.to_lowercase().as_str() { + "tex" | "sty" | "cls" | "def" | "lco" | "aux" | "rnw" => Some(Self::Latex), + "bib" | "bibtex" => Some(Self::Bibtex), + "log" => Some(Self::BuildLog), + _ => None, + } + } + + pub fn by_language_id(language_id: &str) -> Option<Self> { + match language_id { + "latex" | "tex" => Some(Self::Latex), + "bibtex" | "bib" => Some(Self::Bibtex), + _ => None, + } + } +} |