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

Commit f615964

Browse files
author
Hendrik van Antwerpen
committed
Add method to load all graphs for a file or directory
1 parent 8ae0463 commit f615964

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

stack-graphs/src/storage.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,18 @@ impl SQLiteReader {
473473
/// Returns a [`Files`][] value that can be used to iterate over all descendants of a
474474
/// file or directory in the database.
475475
pub fn list_file_or_directory<'a>(
476-
&'a mut self,
476+
&'a self,
477+
file_or_directory: &Path,
478+
) -> Result<Files<'a, [String; 1]>> {
479+
Self::list_file_or_directory_inner(&self.conn, file_or_directory)
480+
}
481+
482+
fn list_file_or_directory_inner<'a>(
483+
conn: &'a Connection,
477484
file_or_directory: &Path,
478485
) -> Result<Files<'a, [String; 1]>> {
479486
let file_or_directory = file_or_directory.to_string_lossy().to_string();
480-
self.conn
481-
.prepare("SELECT file, tag, error FROM graphs WHERE path_descendant_of(file, ?)")
487+
conn.prepare("SELECT file, tag, error FROM graphs WHERE path_descendant_of(file, ?)")
482488
.map(|stmt| Files(stmt, [file_or_directory]))
483489
.map_err(|e| e.into())
484490
}
@@ -507,6 +513,24 @@ impl SQLiteReader {
507513
Ok(())
508514
}
509515

516+
pub fn load_graph_for_file_or_directory(
517+
&mut self,
518+
file_or_directory: &Path,
519+
cancellation_flag: &dyn CancellationFlag,
520+
) -> Result<()> {
521+
for file in Self::list_file_or_directory_inner(&self.conn, file_or_directory)?.try_iter()? {
522+
cancellation_flag.check("loading graphs")?;
523+
let file = file?;
524+
Self::load_graph_for_file_inner(
525+
&file.path.to_string_lossy(),
526+
&mut self.graph,
527+
&mut self.loaded_graphs,
528+
&self.conn,
529+
)?;
530+
}
531+
Ok(())
532+
}
533+
510534
/// Ensure the paths starting a the given node are loaded.
511535
fn load_paths_for_node(
512536
&mut self,

0 commit comments

Comments
 (0)