@@ -287,21 +287,22 @@ auto rebuild_model_indexes(const config::TaskConfig& config, ProjectModel& model
287287
288288// / Populate module information from scan cache into the project model.
289289auto build_module_info (ProjectModel& model, const ScanCache& scan_cache) -> void {
290+ namespace fs = std::filesystem;
291+
290292 for (auto & [file_path, scan_result] : scan_cache) {
291293 if (scan_result.module_name .empty ()) continue ;
292294
293295 model.uses_modules = true ;
294296
295- auto & mod_unit = model.modules [scan_result.module_name ];
297+ auto source_file = fs::path (file_path).lexically_normal ().generic_string ();
298+ auto & mod_unit = model.modules [source_file];
296299 mod_unit.name = scan_result.module_name ;
297300 mod_unit.is_interface = scan_result.is_interface_unit ;
298- mod_unit.source_file = file_path ;
301+ mod_unit.source_file = source_file ;
299302 mod_unit.imports = scan_result.module_imports ;
300303
301304 // Associate symbols from that file to this module unit
302- namespace fs = std::filesystem;
303- auto generic_path = fs::path (file_path).generic_string ();
304- auto file_it = model.files .find (generic_path);
305+ auto file_it = model.files .find (source_file);
305306 if (file_it != model.files .end ()) {
306307 mod_unit.symbols = file_it->second .symbols ;
307308 }
@@ -398,38 +399,29 @@ auto extract_project(const config::TaskConfig& config)
398399 current_file_info.path = normalized;
399400 std::size_t includes_kept = 0 ;
400401
401- if (cache_it != scan_cache.end ()) {
402- for (auto & inc : cache_it->second .includes ) {
403- namespace fs = std::filesystem;
404- auto inc_path = fs::path (inc.path );
405- if (inc_path.is_relative ()) {
406- inc_path = fs::path (entry.directory ) / inc_path;
407- }
408- inc_path = inc_path.lexically_normal ();
409- if (matches_filter (inc_path.string (), config.filter , filter_root)) {
410- append_unique (current_file_info.includes , inc_path.generic_string ());
411- ++includes_kept;
412- }
413- }
414- } else {
402+ if (cache_it == scan_cache.end ()) {
415403 logging::warn (" scan cache miss for {}, re-scanning" , entry.file );
416404 auto scan_result = scan_file (entry);
417405 if (!scan_result.has_value ()) {
418406 return std::unexpected (ExtractError{
419407 .message = std::format (" failed to scan includes for {}: {}" ,
420408 entry.file , scan_result.error ().message )});
421409 }
422- for (auto & inc : scan_result->includes ) {
423- namespace fs = std::filesystem;
424- auto inc_path = fs::path (inc.path );
425- if (inc_path.is_relative ()) {
426- inc_path = fs::path (entry.directory ) / inc_path;
427- }
428- inc_path = inc_path.lexically_normal ();
429- if (matches_filter (inc_path.string (), config.filter , filter_root)) {
430- append_unique (current_file_info.includes , inc_path.generic_string ());
431- ++includes_kept;
432- }
410+
411+ auto [rescanned_it, _] = scan_cache.insert_or_assign (cache_key, std::move (*scan_result));
412+ cache_it = rescanned_it;
413+ }
414+
415+ for (auto & inc : cache_it->second .includes ) {
416+ namespace fs = std::filesystem;
417+ auto inc_path = fs::path (inc.path );
418+ if (inc_path.is_relative ()) {
419+ inc_path = fs::path (entry.directory ) / inc_path;
420+ }
421+ inc_path = inc_path.lexically_normal ();
422+ if (matches_filter (inc_path.string (), config.filter , filter_root)) {
423+ append_unique (current_file_info.includes , inc_path.generic_string ());
424+ ++includes_kept;
433425 }
434426 }
435427
@@ -510,9 +502,9 @@ auto extract_project(const config::TaskConfig& config)
510502 build_module_info (model, scan_cache);
511503 if (model.uses_modules ) {
512504 logging::info (" detected {} module units" , model.modules .size ());
513- for (auto & [name , mod] : model.modules ) {
505+ for (auto & [source_file , mod] : model.modules ) {
514506 logging::info (" module '{}' (interface={}) from {}" ,
515- name, mod.is_interface , mod. source_file );
507+ mod. name , mod.is_interface , source_file);
516508 }
517509 }
518510
0 commit comments