Skip to content

Commit

Permalink
Use bibliographies from BIBINPUTS (#912)
Browse files Browse the repository at this point in the history
See #493.
  • Loading branch information
pfoerster authored Aug 5, 2023
1 parent 78d2b25 commit 2ad91f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

- Use bibliographies found in `BIBINPUTS` environment variable ([#493](https://github.com/latex-lsp/texlab/issues/493))

## [5.8.0] - 2023-07-30

### Added
Expand Down
4 changes: 4 additions & 0 deletions crates/distro/src/file_name_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
16 changes: 15 additions & 1 deletion crates/distro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand All @@ -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 })
}
}

0 comments on commit 2ad91f7

Please sign in to comment.