diff --git a/CHANGELOG.md b/CHANGELOG.md index a97c7cb4..e64e7e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + +- Use bibliographies found in `BIBINPUTS` environment variable ([#493](https://github.com/latex-lsp/texlab/issues/493)) + ## [5.8.0] - 2023-07-30 ### Added diff --git a/crates/distro/src/file_name_db.rs b/crates/distro/src/file_name_db.rs index 750ed11e..06871bde 100644 --- a/crates/distro/src/file_name_db.rs +++ b/crates/distro/src/file_name_db.rs @@ -47,6 +47,10 @@ pub struct FileNameDB { } impl FileNameDB { + pub(crate) fn insert(&mut self, path: PathBuf) { + self.files.insert(DistroFile(path)); + } + pub fn get(&self, name: &str) -> Option<&Path> { self.files.get(name).map(|file| file.path()) } diff --git a/crates/distro/src/lib.rs b/crates/distro/src/lib.rs index 5ad9a852..5c0dbe51 100644 --- a/crates/distro/src/lib.rs +++ b/crates/distro/src/lib.rs @@ -58,7 +58,7 @@ impl Distro { } }; - let file_name_db = match kind { + let mut file_name_db = match kind { DistroKind::Texlive => { let root_dirs = kpsewhich::root_directories()?; FileNameDB::parse(&root_dirs, &mut texlive::read_database)? @@ -70,6 +70,20 @@ impl Distro { DistroKind::Tectonic | DistroKind::Unknown => FileNameDB::default(), }; + if let Some(bibinputs) = std::env::var_os("BIBINPUTS") { + for dir in std::env::split_paths(&bibinputs) { + if let Ok(entries) = std::fs::read_dir(dir) { + for file in entries + .flatten() + .filter(|entry| entry.file_type().map_or(false, |ty| ty.is_file())) + .map(|entry| entry.path()) + { + file_name_db.insert(file); + } + } + } + } + Ok(Self { kind, file_name_db }) } }