Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bibliographies from BIBINPUTS #912

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 })
}
}