@@ -1050,9 +1050,6 @@ impl IndexFacade {
10501050 // Mutation Methods (delegate to Pipeline)
10511051 // =========================================================================
10521052
1053- /// Index a single file using the parallel pipeline.
1054- ///
1055- /// Returns `IndexingResult::Indexed` with the file ID on success.
10561053 /// File records key off path text: an uncanonical root or file path
10571054 /// (`./src`, `x/../x`) addresses a key space disjoint from the
10581055 /// registered indexed_paths walks, re-indexing every file as new and
@@ -1108,6 +1105,7 @@ impl IndexFacade {
11081105 . collect ( )
11091106 }
11101107
1108+ /// Index a single file, returning `Cached` when its content hash is unchanged.
11111109 pub fn index_file (
11121110 & mut self ,
11131111 path : impl AsRef < std:: path:: Path > ,
@@ -1125,7 +1123,11 @@ impl IndexFacade {
11251123 self . embedding_pool . clone ( ) ,
11261124 ) ?;
11271125
1128- Ok ( crate :: IndexingResult :: Indexed ( stats. file_id ) )
1126+ if stats. cached {
1127+ Ok ( crate :: IndexingResult :: Cached ( stats. file_id ) )
1128+ } else {
1129+ Ok ( crate :: IndexingResult :: Indexed ( stats. file_id ) )
1130+ }
11291131 }
11301132
11311133 /// Index a single file with optional force re-indexing.
@@ -4603,4 +4605,40 @@ mod tests {
46034605 . unwrap ( ) ;
46044606 assert_cross_root_edge ( & facade, "post-edit" ) ;
46054607 }
4608+
4609+ // Lock for the pipeline's cached result: a second index of unchanged
4610+ // content is `Cached`; an edit is `Indexed` again and replaces the
4611+ // symbols.
4612+ #[ test]
4613+ fn index_file_returns_cached_for_unchanged_content_and_indexed_for_an_edit ( ) {
4614+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
4615+ let root = dir. path ( ) . canonicalize ( ) . unwrap ( ) . join ( "src" ) ;
4616+ std:: fs:: create_dir_all ( & root) . unwrap ( ) ;
4617+ let file = root. join ( "a.py" ) ;
4618+ std:: fs:: write ( & file, "def alpha():\n pass\n " ) . unwrap ( ) ;
4619+ let mut settings = Settings {
4620+ index_path : dir. path ( ) . join ( "index" ) ,
4621+ workspace_root : None ,
4622+ ..Default :: default ( )
4623+ } ;
4624+ settings. add_indexed_path ( root. clone ( ) ) . unwrap ( ) ;
4625+ let mut facade = IndexFacade :: new ( std:: sync:: Arc :: new ( settings) ) . unwrap ( ) ;
4626+
4627+ let first = facade. index_file ( & file) . unwrap ( ) ;
4628+ let crate :: IndexingResult :: Indexed ( file_id) = first else {
4629+ panic ! ( "first index: expected Indexed, got {first:?}" ) ;
4630+ } ;
4631+ assert_eq ! (
4632+ facade. index_file( & file) . unwrap( ) ,
4633+ crate :: IndexingResult :: Cached ( file_id)
4634+ ) ;
4635+
4636+ std:: fs:: write ( & file, "def beta():\n pass\n " ) . unwrap ( ) ;
4637+ assert ! ( matches!(
4638+ facade. index_file( & file) . unwrap( ) ,
4639+ crate :: IndexingResult :: Indexed ( _)
4640+ ) ) ;
4641+ assert ! ( facade. find_symbols_by_name( "alpha" , None ) . is_empty( ) ) ;
4642+ assert_eq ! ( facade. find_symbols_by_name( "beta" , None ) . len( ) , 1 ) ;
4643+ }
46064644}
0 commit comments