@@ -6,7 +6,9 @@ use stack_graphs::storage::{SQLiteReader, SQLiteWriter};
66use tree_sitter_stack_graphs:: cli:: util:: { SourcePosition , SourceSpan } ;
77use tree_sitter_stack_graphs:: loader:: Loader ;
88
9- use crate :: stack_graphs_wrapper:: { index_all, new_loader, query_definition} ;
9+ use crate :: stack_graphs_wrapper:: {
10+ get_status, get_status_all, index_all, new_loader, query_definition,
11+ } ;
1012
1113#[ pyclass]
1214#[ derive( Clone ) ]
@@ -17,6 +19,77 @@ pub enum Language {
1719 Java ,
1820}
1921
22+ #[ pyclass]
23+ #[ derive( Clone ) ]
24+ pub enum FileStatus {
25+ Missing ,
26+ Indexed ,
27+ Error ,
28+ }
29+
30+ #[ pyclass]
31+ #[ derive( Clone ) ]
32+ pub struct FileEntry {
33+ #[ pyo3( get) ]
34+ pub path : String ,
35+ #[ pyo3( get) ]
36+ pub tag : String ,
37+ #[ pyo3( get) ]
38+ pub status : FileStatus ,
39+ // As pyo3 does not support string enums, we use Option<String> here instead.
40+ #[ pyo3( get) ]
41+ pub error : Option < String > ,
42+ }
43+
44+ impl From < stack_graphs:: storage:: FileEntry > for FileEntry {
45+ fn from ( entry : stack_graphs:: storage:: FileEntry ) -> Self {
46+ let status = match entry. status {
47+ stack_graphs:: storage:: FileStatus :: Missing => FileStatus :: Missing ,
48+ stack_graphs:: storage:: FileStatus :: Indexed => FileStatus :: Indexed ,
49+ stack_graphs:: storage:: FileStatus :: Error ( _) => FileStatus :: Error ,
50+ } ;
51+
52+ let error = match entry. status {
53+ stack_graphs:: storage:: FileStatus :: Error ( e) => Some ( e) ,
54+ _ => None ,
55+ } ;
56+
57+ FileEntry {
58+ path : entry. path . to_str ( ) . unwrap ( ) . to_string ( ) ,
59+ tag : entry. tag ,
60+ status,
61+ error,
62+ }
63+ }
64+ }
65+
66+ #[ pymethods]
67+ impl FileEntry {
68+ fn __repr__ ( & self ) -> String {
69+ match self {
70+ FileEntry {
71+ path,
72+ tag,
73+ status,
74+ error,
75+ } => {
76+ let error = match error {
77+ Some ( e) => format ! ( "(\" {}\" )" , e) ,
78+ None => "" . to_string ( ) ,
79+ } ;
80+
81+ format ! (
82+ "FileEntry(path=\" {}\" , tag=\" {}\" , status={}{})" ,
83+ path,
84+ tag,
85+ status. __pyo3__repr__( ) ,
86+ error
87+ )
88+ }
89+ }
90+ }
91+ }
92+
2093#[ pyclass]
2194#[ derive( Clone ) ]
2295pub struct Position {
@@ -66,6 +139,7 @@ impl Querier {
66139#[ pyclass]
67140pub struct Indexer {
68141 db_writer : SQLiteWriter ,
142+ db_reader : SQLiteReader ,
69143 db_path : String ,
70144 loader : Loader ,
71145}
@@ -76,6 +150,7 @@ impl Indexer {
76150 pub fn new ( db_path : String , languages : Vec < Language > ) -> Self {
77151 Indexer {
78152 db_writer : SQLiteWriter :: open ( db_path. clone ( ) ) . unwrap ( ) ,
153+ db_reader : SQLiteReader :: open ( db_path. clone ( ) ) . unwrap ( ) ,
79154 db_path : db_path,
80155 loader : new_loader ( languages) ,
81156 }
@@ -91,8 +166,22 @@ impl Indexer {
91166 }
92167 }
93168
94- // @TODO: Add a method to retrieve the status of the files (indexed, failed, etc.)
95- // This might be done on a separate class (Database / Storage), as it is tied to the storage, not a specific indexer
169+ pub fn status ( & mut self , paths : Vec < String > ) -> PyResult < Vec < FileEntry > > {
170+ let paths: Vec < std:: path:: PathBuf > =
171+ paths. iter ( ) . map ( |p| std:: path:: PathBuf :: from ( p) ) . collect ( ) ;
172+
173+ get_status ( paths, & mut self . db_reader ) ?
174+ . into_iter ( )
175+ . map ( |e| Ok ( e. into ( ) ) )
176+ . collect ( )
177+ }
178+
179+ pub fn status_all ( & mut self ) -> PyResult < Vec < FileEntry > > {
180+ get_status_all ( & mut self . db_reader ) ?
181+ . into_iter ( )
182+ . map ( |e| Ok ( e. into ( ) ) )
183+ . collect ( )
184+ }
96185
97186 fn __repr__ ( & self ) -> String {
98187 format ! ( "Indexer(db_path=\" {}\" )" , self . db_path)
0 commit comments