diff options
author | Norbert Preining <norbert@preining.info> | 2023-01-22 03:01:36 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-01-22 03:01:36 +0000 |
commit | 328cc6eb536476a95a84cd7de863b32cabc41b0e (patch) | |
tree | 6ce563a6c5075adedee625e648ab6e1fd86a0052 /support/texlab/src/db/workspace.rs | |
parent | 94c0d48361932b4beca57cc5609d26a46270dfeb (diff) |
CTAN sync 202301220301
Diffstat (limited to 'support/texlab/src/db/workspace.rs')
-rw-r--r-- | support/texlab/src/db/workspace.rs | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/support/texlab/src/db/workspace.rs b/support/texlab/src/db/workspace.rs index b8bdb27f1f..0fb9745b12 100644 --- a/support/texlab/src/db/workspace.rs +++ b/support/texlab/src/db/workspace.rs @@ -11,7 +11,6 @@ use rustc_hash::FxHashSet; use crate::{ db::document::{Document, Location}, distro::FileNameDB, - util::HOME_DIR, Db, Options, }; @@ -154,49 +153,31 @@ impl Workspace { } } -const SPECIAL_ENTRIES: &[&str] = &[ - ".git", - "Tectonic.toml", - ".latexmkrc", - "latexmkrc", - ".chktexrc", - "chktexrc", -]; - #[salsa::tracked] impl Workspace { #[salsa::tracked] pub fn working_dir(self, db: &dyn Db, base_dir: Location) -> Location { - let mut path = self + if let Some(dir) = self .options(db) .root_directory .as_deref() .and_then(|path| path.to_str()) - .or_else(|| { - for dir in base_dir - .path(db) - .as_deref()? - .ancestors() - .skip(1) - .filter(|path| Some(*path) != HOME_DIR.as_deref()) - { - for name in SPECIAL_ENTRIES { - if dir.join(name).exists() { - return Some(dir.to_str()?); - } - } - } - - None - }) - .unwrap_or(".") - .to_string(); - - if !path.ends_with(".") { - path.push('/'); + .and_then(|path| base_dir.join(db, path)) + { + return dir; } - base_dir.join(db, &path).unwrap_or(base_dir) + self.documents(db) + .iter() + .filter(|doc| matches!(doc.language(db), Language::TexlabRoot | Language::Tectonic)) + .filter_map(|doc| doc.location(db).join(db, ".")) + .find(|root_dir| { + base_dir + .uri(db) + .as_str() + .starts_with(root_dir.uri(db).as_str()) + }) + .unwrap_or(base_dir) } #[salsa::tracked] |