diff --git a/stack-graphs/CHANGELOG.md b/stack-graphs/CHANGELOG.md index 20dc1bfd6..d9816a707 100644 --- a/stack-graphs/CHANGELOG.md +++ b/stack-graphs/CHANGELOG.md @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New `SQLiteReader::clear` and `SQLiteReader::clear_paths` methods that make it easier to reuse instances. +- The method `SQLiteReader::load_graph_for_file` now returns the file handle for the loaded file. ### Changed - The `Appendable` trait has been simplified. Its `Ctx` type parameter is gone, in favor of a separate trait `ToAppendable` that is used to find appendables for a handle. The type itself moved from the `cycles` to the `stitching` module. - The `ForwardPartialPathStitcher` has been generalized so that it can be used to build paths from a database or from graph edges. It now takes a type parameter indicating the type of candidates it uses. Instead of a `Database` instance, it expects a value that implements the `Candidates` and `ToAppendable` traits. The `ForwardPartialPathStitcher::process_next_phase` expects an additional `extend_until` closure that controls whether the extended paths are considered for further extension or not (using `|_,_,_| true` retains old behavior). - The SQLite database implementation is using a new schema which stores binary instead of JSON values, resulting in faster write times and smaller databases. +- Renamed method `SQLiteReader::load_graph_for_file_or_directory` to `SQLiteReader::load_graphs_for_file_or_directory`. ### Fixed diff --git a/stack-graphs/src/arena.rs b/stack-graphs/src/arena.rs index 52334a638..6e4747267 100644 --- a/stack-graphs/src/arena.rs +++ b/stack-graphs/src/arena.rs @@ -183,6 +183,7 @@ impl Arena { /// Clear the arena, keeping underlying allocated capacity. After this, all previous handles into /// the arena are invalid. + #[cfg_attr(not(feature = "storage"), allow(dead_code))] #[inline(always)] pub(crate) fn clear(&mut self) { self.items.clear(); @@ -289,6 +290,7 @@ impl SupplementalArena { /// Clear the supplemantal arena, keeping underlying allocated capacity. After this, /// all previous handles into the arena are invalid. + #[cfg_attr(not(feature = "storage"), allow(dead_code))] #[inline(always)] pub(crate) fn clear(&mut self) { self.items.clear(); diff --git a/stack-graphs/src/partial.rs b/stack-graphs/src/partial.rs index a46fb88a4..bec688a4b 100644 --- a/stack-graphs/src/partial.rs +++ b/stack-graphs/src/partial.rs @@ -2625,6 +2625,7 @@ impl PartialPaths { } } + #[cfg_attr(not(feature = "storage"), allow(dead_code))] pub(crate) fn clear(&mut self) { self.partial_symbol_stacks.clear(); self.partial_scope_stacks.clear(); diff --git a/stack-graphs/src/stitching.rs b/stack-graphs/src/stitching.rs index 550ecd911..cf1ecbdd7 100644 --- a/stack-graphs/src/stitching.rs +++ b/stack-graphs/src/stitching.rs @@ -251,6 +251,7 @@ impl Database { /// Clear the database. After this, all previous handles into the database are /// invalid. + #[cfg_attr(not(feature = "storage"), allow(dead_code))] pub(crate) fn clear(&mut self) { self.partial_paths.clear(); self.local_nodes.clear(); diff --git a/stack-graphs/src/storage.rs b/stack-graphs/src/storage.rs index 89d9a843b..2aae6d219 100644 --- a/stack-graphs/src/storage.rs +++ b/stack-graphs/src/storage.rs @@ -507,7 +507,7 @@ impl SQLiteReader { } /// Ensure the graph for the given file is loaded. - pub fn load_graph_for_file(&mut self, file: &str) -> Result<()> { + pub fn load_graph_for_file(&mut self, file: &str) -> Result> { Self::load_graph_for_file_inner(file, &mut self.graph, &mut self.loaded_graphs, &self.conn) } @@ -516,21 +516,21 @@ impl SQLiteReader { graph: &mut StackGraph, loaded_graphs: &mut HashSet, conn: &Connection, - ) -> Result<()> { + ) -> Result> { copious_debugging!("--> Load graph for {}", file); if !loaded_graphs.insert(file.to_string()) { copious_debugging!(" * Already loaded"); - return Ok(()); + return Ok(graph.get_file(file).expect("loaded file to exist")); } copious_debugging!(" * Load from database"); let mut stmt = conn.prepare_cached("SELECT value FROM graphs WHERE file = ?")?; let value = stmt.query_row([file], |row| row.get::<_, Vec>(0))?; let file_graph = rmp_serde::from_slice::(&value)?; file_graph.load_into(graph)?; - Ok(()) + Ok(graph.get_file(file).expect("loaded file to exist")) } - pub fn load_graph_for_file_or_directory( + pub fn load_graphs_for_file_or_directory( &mut self, file_or_directory: &Path, cancellation_flag: &dyn CancellationFlag, diff --git a/tree-sitter-stack-graphs/src/cli/visualize.rs b/tree-sitter-stack-graphs/src/cli/visualize.rs index 3b3b6e1eb..fd947c1d9 100644 --- a/tree-sitter-stack-graphs/src/cli/visualize.rs +++ b/tree-sitter-stack-graphs/src/cli/visualize.rs @@ -45,7 +45,7 @@ impl VisualizeArgs { let mut db = SQLiteReader::open(&db_path)?; for source_path in &self.source_paths { let source_path = source_path.canonicalize()?; - db.load_graph_for_file_or_directory(&source_path, cancellation_flag)?; + db.load_graphs_for_file_or_directory(&source_path, cancellation_flag)?; } let (graph, _, _) = db.get(); let starting_nodes = graph