Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit bee8826

Browse files
author
Hendrik van Antwerpen
committed
Small tweaks to the storage API
1 parent dd67086 commit bee8826

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

stack-graphs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- New `SQLiteReader::clear` and `SQLiteReader::clear_paths` methods that make it easier to reuse instances.
13+
- The method `SQLiteReader::load_graph_for_file` now returns the file handle for the loaded file.
1314

1415
### Changed
1516

1617
- 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.
1718
- 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).
1819
- The SQLite database implementation is using a new schema which stores binary instead of JSON values, resulting in faster write times and smaller databases.
20+
- Renamed method `SQLiteReader::load_graph_for_file_or_directory` to `SQLiteReader::load_graphs_for_file_or_directory`.
1921

2022
### Fixed
2123

stack-graphs/src/arena.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<T> Arena<T> {
183183

184184
/// Clear the arena, keeping underlying allocated capacity. After this, all previous handles into
185185
/// the arena are invalid.
186+
#[cfg_attr(not(feature = "storage"), allow(dead_code))]
186187
#[inline(always)]
187188
pub(crate) fn clear(&mut self) {
188189
self.items.clear();
@@ -289,6 +290,7 @@ impl<H, T> SupplementalArena<H, T> {
289290

290291
/// Clear the supplemantal arena, keeping underlying allocated capacity. After this,
291292
/// all previous handles into the arena are invalid.
293+
#[cfg_attr(not(feature = "storage"), allow(dead_code))]
292294
#[inline(always)]
293295
pub(crate) fn clear(&mut self) {
294296
self.items.clear();

stack-graphs/src/partial.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,7 @@ impl PartialPaths {
26252625
}
26262626
}
26272627

2628+
#[cfg_attr(not(feature = "storage"), allow(dead_code))]
26282629
pub(crate) fn clear(&mut self) {
26292630
self.partial_symbol_stacks.clear();
26302631
self.partial_scope_stacks.clear();

stack-graphs/src/stitching.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ impl Database {
251251

252252
/// Clear the database. After this, all previous handles into the database are
253253
/// invalid.
254+
#[cfg_attr(not(feature = "storage"), allow(dead_code))]
254255
pub(crate) fn clear(&mut self) {
255256
self.partial_paths.clear();
256257
self.local_nodes.clear();

stack-graphs/src/storage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl SQLiteReader {
507507
}
508508

509509
/// Ensure the graph for the given file is loaded.
510-
pub fn load_graph_for_file(&mut self, file: &str) -> Result<()> {
510+
pub fn load_graph_for_file(&mut self, file: &str) -> Result<Handle<File>> {
511511
Self::load_graph_for_file_inner(file, &mut self.graph, &mut self.loaded_graphs, &self.conn)
512512
}
513513

@@ -516,21 +516,21 @@ impl SQLiteReader {
516516
graph: &mut StackGraph,
517517
loaded_graphs: &mut HashSet<String>,
518518
conn: &Connection,
519-
) -> Result<()> {
519+
) -> Result<Handle<File>> {
520520
copious_debugging!("--> Load graph for {}", file);
521521
if !loaded_graphs.insert(file.to_string()) {
522522
copious_debugging!(" * Already loaded");
523-
return Ok(());
523+
return Ok(graph.get_file(file).expect("loaded file to exist"));
524524
}
525525
copious_debugging!(" * Load from database");
526526
let mut stmt = conn.prepare_cached("SELECT value FROM graphs WHERE file = ?")?;
527527
let value = stmt.query_row([file], |row| row.get::<_, Vec<u8>>(0))?;
528528
let file_graph = rmp_serde::from_slice::<serde::StackGraph>(&value)?;
529529
file_graph.load_into(graph)?;
530-
Ok(())
530+
Ok(graph.get_file(file).expect("loaded file to exist"))
531531
}
532532

533-
pub fn load_graph_for_file_or_directory(
533+
pub fn load_graphs_for_file_or_directory(
534534
&mut self,
535535
file_or_directory: &Path,
536536
cancellation_flag: &dyn CancellationFlag,

tree-sitter-stack-graphs/src/cli/visualize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl VisualizeArgs {
4545
let mut db = SQLiteReader::open(&db_path)?;
4646
for source_path in &self.source_paths {
4747
let source_path = source_path.canonicalize()?;
48-
db.load_graph_for_file_or_directory(&source_path, cancellation_flag)?;
48+
db.load_graphs_for_file_or_directory(&source_path, cancellation_flag)?;
4949
}
5050
let (graph, _, _) = db.get();
5151
let starting_nodes = graph

0 commit comments

Comments
 (0)