@@ -118,7 +118,8 @@ impl Backend {
118118 // classes that don't follow PSR-4 conventions and aren't in the
119119 // Composer classmap — e.g. global-namespace classes like `Mockery`
120120 // that are loaded via Composer's `files` autoloading.
121- if let Some ( file_uri) = self . class_index . read ( ) . get ( class_name) . cloned ( )
121+ let class_index_uri = self . class_index . read ( ) . get ( class_name) . cloned ( ) ;
122+ if let Some ( file_uri) = class_index_uri
122123 && let Some ( file_path) = Url :: parse ( & file_uri)
123124 . ok ( )
124125 . and_then ( |u| u. to_file_path ( ) . ok ( ) )
@@ -456,15 +457,21 @@ impl Backend {
456457 // thousands of vendor files. See P13.
457458
458459 // Populate the fqn_index so that `find_class_in_ast_map` can
459- // resolve these classes via O(1) hash lookup.
460+ // resolve these classes via O(1) hash lookup. Also populate
461+ // class_index (FQN → URI) so that `find_class_file_content` can
462+ // locate the source file even after the ast_map entry is cleared
463+ // by didClose. The class_index cost is negligible (one string
464+ // pair per class).
460465 {
461466 let mut fqn_idx = self . fqn_index . write ( ) ;
467+ let mut class_idx = self . class_index . write ( ) ;
462468 for cls in & arc_classes {
463469 if cls. name . starts_with ( "__anonymous@" ) {
464470 continue ;
465471 }
466472 let fqn = cls. fqn ( ) . to_string ( ) ;
467- fqn_idx. insert ( fqn, Arc :: clone ( cls) ) ;
473+ fqn_idx. insert ( fqn. clone ( ) , Arc :: clone ( cls) ) ;
474+ class_idx. entry ( fqn) . or_insert_with ( || uri. to_owned ( ) ) ;
468475 }
469476 }
470477
0 commit comments