Use rootDirectory setting to resolve output files

This commit is contained in:
Patrick Förster 2020-02-26 19:12:42 +01:00
parent a675ddffe0
commit 54d0651c5c
3 changed files with 20 additions and 5 deletions

1
Cargo.lock generated
View file

@ -2156,6 +2156,7 @@ name = "texlab-protocol"
version = "0.1.0"
dependencies = [
"bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-boxed 0.1.0",
"jsonrpc 0.1.0",

View file

@ -8,6 +8,7 @@ edition = "2018"
[dependencies]
bytes = "0.5"
dunce = "1.0"
futures = "0.3"
futures-boxed = { path = "../futures_boxed" }
jsonrpc = { path = "../jsonrpc" }

View file

@ -88,12 +88,25 @@ impl Options {
pub fn resolve_output_file(&self, tex_path: &Path, extension: &str) -> Option<PathBuf> {
let stem = tex_path.file_stem()?.to_str()?;
let name = format!("{}.{}", stem, extension);
let output_directory = self
.latex
self.latex
.as_ref()
.and_then(|latex| latex.build.as_ref())
.and_then(|build| build.output_directory.clone())
.unwrap_or_else(|| PathBuf::from("."));
Some(tex_path.parent()?.join(output_directory).join(name))
.and_then(|build| build.output_directory.as_ref())
.map(|path| path.join(&name))
.and_then(|path| dunce::canonicalize(path).ok())
.or_else(|| {
self.latex
.as_ref()
.and_then(|latex| latex.root_directory.as_ref())
.map(|path| path.join(&name))
.and_then(|path| dunce::canonicalize(path).ok())
})
.or_else(|| {
tex_path
.parent()
.map(|path| path.join(&name))
.and_then(|path| dunce::canonicalize(path).ok())
})
}
}