diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab49b01..baf15de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `texlab.experimental.mathEnvironments` - `texlab.experimental.enumEnvironments` - `texlab.experimental.verbatimEnvironments` +- Add `texlab.changeEnvironment` workspace command ([#849](https://github.com/latex-lsp/texlab/issues/849)) +- Add `texlab.showDependencyGraph` workspace command ### Changed diff --git a/src/db/discovery.rs b/src/db/discovery.rs index 12338f74..9cc5a4e8 100644 --- a/src/db/discovery.rs +++ b/src/db/discovery.rs @@ -40,8 +40,11 @@ pub fn hidden_dependencies( base_dir: Location, dependencies: &mut Vec, ) { - dependencies.extend(hidden_dependency(db, document, base_dir, "log")); - dependencies.extend(hidden_dependency(db, document, base_dir, "aux")); + let uri = document.location(db).uri(db).as_str(); + if document.language(db) == Language::Tex && !uri.ends_with(".aux") { + dependencies.extend(hidden_dependency(db, document, base_dir, "log")); + dependencies.extend(hidden_dependency(db, document, base_dir, "aux")); + } } #[salsa::tracked] @@ -158,7 +161,7 @@ impl DependencyGraph { } } -#[salsa::tracked] +#[salsa::tracked(return_ref)] pub fn dependency_graph(db: &dyn Db, start: Document) -> DependencyGraph { let workspace = Workspace::get(db); diff --git a/src/features/definition/document.rs b/src/features/definition/document.rs index 58237f75..40cfdf1d 100644 --- a/src/features/definition/document.rs +++ b/src/features/definition/document.rs @@ -12,7 +12,7 @@ pub(super) fn goto_definition(context: &CursorContext) -> Option Result { + let workspace = Workspace::get(db); + + let documents = workspace + .documents(db) + .iter() + .enumerate() + .map(|(i, doc)| (*doc, format!("v{i:0>5}"))) + .collect::>(); + + let mut writer = Vec::new(); + writeln!(&mut writer, "digraph G {{")?; + writeln!(&mut writer, "rankdir = LR;")?; + + for (document, node) in &documents { + let label = document.location(db).uri(db).as_str(); + let shape = if document.can_be_root(db) { + "tripleoctagon" + } else if document.can_be_built(db) { + "doubleoctagon" + } else { + "octagon" + }; + + writeln!(&mut writer, "\t{node} [label=\"{label}\", shape={shape}];")?; + } + + for edge in workspace + .documents(db) + .iter() + .flat_map(|start| dependency_graph(db, *start).edges.iter()) + .unique() + { + let source = &documents[&edge.source]; + let target = &documents[&edge.target]; + let label = edge + .origin + .as_ref() + .map_or("", |origin| &origin.link.path(db).text(db)); + + writeln!(&mut writer, "\t{source} -> {target} [label=\"{label}\"];")?; + } + + writeln!(&mut writer, "}}")?; + Ok(String::from_utf8(writer)?) +} diff --git a/src/server.rs b/src/server.rs index 45475afa..bf0ef642 100644 --- a/src/server.rs +++ b/src/server.rs @@ -29,7 +29,7 @@ use crate::{ completion::{self, builder::CompletionItemData}, definition, folding, formatting, forward_search, highlight, hover, inlay_hint, link, reference, rename, symbol, - workspace_command::{change_environment, clean}, + workspace_command::{change_environment, clean, dep_graph}, }, normalize_uri, syntax::bibtex, @@ -675,6 +675,9 @@ impl Server { change_environment::change_environment(db, params.arguments) }); } + "texlab.showDependencyGraph" => { + self.run_with_db(id, move |db| dep_graph::show_dependency_graph(db).unwrap()); + } _ => { self.client .send_error(