diff options
Diffstat (limited to 'support/texlab/crates/commands')
-rw-r--r-- | support/texlab/crates/commands/Cargo.toml | 4 | ||||
-rw-r--r-- | support/texlab/crates/commands/src/build.rs | 12 | ||||
-rw-r--r-- | support/texlab/crates/commands/src/clean.rs | 8 | ||||
-rw-r--r-- | support/texlab/crates/commands/src/dep_graph.rs | 31 | ||||
-rw-r--r-- | support/texlab/crates/commands/src/fwd_search.rs | 18 |
5 files changed, 42 insertions, 31 deletions
diff --git a/support/texlab/crates/commands/Cargo.toml b/support/texlab/crates/commands/Cargo.toml index 512a05ee61..bebcde27af 100644 --- a/support/texlab/crates/commands/Cargo.toml +++ b/support/texlab/crates/commands/Cargo.toml @@ -10,14 +10,14 @@ rust-version.workspace = true anyhow = "1.0.72" base-db = { path = "../base-db" } bstr = "1.9.0" -crossbeam-channel = "0.5.11" +crossbeam-channel = "0.5.12" itertools = "0.12.0" libc = "0.2.153" log = "0.4.21" rowan = "0.15.15" rustc-hash = "1.1.0" syntax = { path = "../syntax" } -thiserror = "1.0.57" +thiserror = "1.0.58" url = "2.5.0" [dev-dependencies] diff --git a/support/texlab/crates/commands/src/build.rs b/support/texlab/crates/commands/src/build.rs index 47e156ef72..34d39f26e4 100644 --- a/support/texlab/crates/commands/src/build.rs +++ b/support/texlab/crates/commands/src/build.rs @@ -6,7 +6,10 @@ use std::{ }; use anyhow::Result; -use base_db::Workspace; +use base_db::{ + deps::{self, ProjectRoot}, + Workspace, +}; use bstr::io::BufReadExt; use crossbeam_channel::Sender; use thiserror::Error; @@ -39,8 +42,7 @@ impl BuildCommand { return Err(BuildError::NotFound(uri.clone())); }; - let document = workspace - .parents(document) + let document = deps::parents(workspace, document) .into_iter() .next() .unwrap_or(document); @@ -53,7 +55,9 @@ impl BuildCommand { let program = config.program.clone(); let args = replace_placeholders(&config.args, &[('f', path)]); - let Ok(working_dir) = workspace.current_dir(&document.dir).to_file_path() else { + let root = ProjectRoot::walk_and_find(workspace, &document.dir); + + let Ok(working_dir) = root.compile_dir.to_file_path() else { return Err(BuildError::NotLocal(document.uri.clone())); }; diff --git a/support/texlab/crates/commands/src/clean.rs b/support/texlab/crates/commands/src/clean.rs index 706e7dfaf1..d4ec6b24f4 100644 --- a/support/texlab/crates/commands/src/clean.rs +++ b/support/texlab/crates/commands/src/clean.rs @@ -1,7 +1,7 @@ use std::process::Stdio; use anyhow::Result; -use base_db::{Document, Workspace}; +use base_db::{deps::ProjectRoot, Document, Workspace}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)] pub enum CleanTarget { @@ -21,7 +21,7 @@ impl CleanCommand { anyhow::bail!("document '{}' is not a local file", document.uri) }; - let base_dir = workspace.current_dir(&document.dir); + let root = ProjectRoot::walk_and_find(workspace, &document.dir); let flag = match target { CleanTarget::Auxiliary => "-c", @@ -29,8 +29,8 @@ impl CleanCommand { }; let out_dir = match target { - CleanTarget::Auxiliary => workspace.aux_dir(&base_dir), - CleanTarget::Artifacts => workspace.pdf_dir(&base_dir), + CleanTarget::Auxiliary => root.aux_dir, + CleanTarget::Artifacts => root.pdf_dir, }; let out_dir_path = out_dir.to_file_path().unwrap(); diff --git a/support/texlab/crates/commands/src/dep_graph.rs b/support/texlab/crates/commands/src/dep_graph.rs index 1388756ddf..fe9ff3829c 100644 --- a/support/texlab/crates/commands/src/dep_graph.rs +++ b/support/texlab/crates/commands/src/dep_graph.rs @@ -1,22 +1,20 @@ use std::io::Write; use anyhow::Result; -use base_db::{graph, Document, Workspace}; +use base_db::Workspace; use itertools::Itertools; use rustc_hash::FxHashMap; pub fn show_dependency_graph(workspace: &Workspace) -> Result<String> { - let documents = workspace - .iter() - .enumerate() - .map(|(i, doc)| (doc, format!("v{i:0>5}"))) - .collect::<FxHashMap<&Document, String>>(); + let mut documents = FxHashMap::default(); let mut writer = Vec::new(); writeln!(&mut writer, "digraph G {{")?; writeln!(&mut writer, "rankdir = LR;")?; - for (document, node) in &documents { + for (i, document) in workspace.iter().enumerate() { + let node = format!("v{i:0>5}"); + let label = document.uri.as_str(); let shape = if document .data @@ -35,19 +33,22 @@ pub fn show_dependency_graph(workspace: &Workspace) -> Result<String> { }; writeln!(&mut writer, "\t{node} [label=\"{label}\", shape={shape}];")?; + documents.insert(&document.uri, node); } for edge in workspace - .iter() - .flat_map(|start| graph::Graph::new(workspace, start).edges) + .graphs() + .values() + .flat_map(|graph| &graph.edges) .unique() { - let source = &documents[edge.source]; - let target = &documents[edge.target]; - let label = edge - .weight - .as_ref() - .map_or("<artifact>", |weight| &weight.link.path.text); + let source = &documents[&edge.source]; + let target = &documents[&edge.target]; + let label = match &edge.data { + base_db::deps::EdgeData::DirectLink(data) => &data.link.path.text, + base_db::deps::EdgeData::AdditionalFiles => "<project>", + base_db::deps::EdgeData::Artifact => "<artifact>", + }; writeln!(&mut writer, "\t{source} -> {target} [label=\"{label}\"];")?; } diff --git a/support/texlab/crates/commands/src/fwd_search.rs b/support/texlab/crates/commands/src/fwd_search.rs index 4e3450681c..f1991cd48e 100644 --- a/support/texlab/crates/commands/src/fwd_search.rs +++ b/support/texlab/crates/commands/src/fwd_search.rs @@ -1,7 +1,10 @@ use std::{path::PathBuf, process::Stdio}; use anyhow::Result; -use base_db::{Document, Workspace}; +use base_db::{ + deps::{self, ProjectRoot}, + Document, Workspace, +}; use thiserror::Error; use url::Url; @@ -53,7 +56,10 @@ impl ForwardSearch { .lookup(uri) .ok_or_else(|| ForwardSearchError::TexNotFound(uri.clone()))?; - let parent = workspace.parents(child).into_iter().next().unwrap_or(child); + let parent = deps::parents(workspace, child) + .into_iter() + .next() + .unwrap_or(child); log::debug!("[FwdSearch] root_document={}", parent.uri,); @@ -78,12 +84,12 @@ impl ForwardSearch { } fn find_pdf(workspace: &Workspace, document: &Document) -> Result<PathBuf, ForwardSearchError> { - let base_dir = workspace.current_dir(&document.dir); - let pdf_dir = workspace.pdf_dir(&base_dir); + let root = ProjectRoot::walk_and_find(workspace, &document.dir); - log::debug!("[FwdSearch] base_dir={base_dir}, pdf_dir={pdf_dir}"); + log::debug!("[FwdSearch] root={root:#?}"); - let pdf_dir = pdf_dir + let pdf_dir = root + .pdf_dir .to_file_path() .map_err(|()| ForwardSearchError::InvalidPath(document.uri.clone()))?; |