diff --git a/uppsrc/ide/IncludeTrick.cpp b/uppsrc/ide/IncludeTrick.cpp index 6f54f6d13..f3d9a415a 100644 --- a/uppsrc/ide/IncludeTrick.cpp +++ b/uppsrc/ide/IncludeTrick.cpp @@ -19,6 +19,7 @@ void AssistEditor::SyncMaster() if(AssistDiagnostics) { PutConsole("Master source " << editfile << " -> " << master_source); + PutConsole("Master chain " << AsString(master_chain)); ppi.WhenBlitzBlock = [=](const String& inc, const String& path) { PutConsole(String() << inc << " blocks BLITZ of " << path); }; diff --git a/uppsrc/ide/clang/Indexer.cpp b/uppsrc/ide/clang/Indexer.cpp index bd804b418..7c0bb2c1d 100644 --- a/uppsrc/ide/clang/Indexer.cpp +++ b/uppsrc/ide/clang/Indexer.cpp @@ -11,7 +11,7 @@ String FindMasterSource(PPInfo& ppi, const Workspace& wspc, const String& header LTIMING("FindMasterSource"); String header_file = NormalizePath(header_file_); - for(int speculative = 0; speculative < 2; speculative++) { + for(int pass = 0; pass < 3; pass++) { VectorMap deps; ArrayMap> dics; for(int i : wspc.use_order) { @@ -20,8 +20,12 @@ String FindMasterSource(PPInfo& ppi, const Workspace& wspc, const String& header for(int i = 0; i < pk.file.GetCount(); i++) { String path = SourcePath(pk_name, pk.file[i]); if(!pk.file[i].separator && ppi.FileExists(path) && !PathIsEqual(header_file, path) && - IsCppSourceFile(path) && GetFileLength(path) < 4000000) { - ppi.GatherDependencies(path, deps, dics, speculative); + IsCppSourceFile(path) && + (pass == 2 || // last chance speculative run, any folder + pass == 0 && GetFileFolder(path) == GetFileFolder(header_file) || // prefer source from the same folder first + pass == 1 && GetFileFolder(path) != GetFileFolder(header_file)) && + GetFileLength(path) < 4000000) { + ppi.GatherDependencies(path, deps, dics, pass > 1); if(deps.Find(header_file) >= 0) return path; } @@ -50,7 +54,7 @@ const VectorMap& FindMasterSourceCached(PPInfo& ppi, const Workspa VectorMap& cache) { String header_file = NormalizePath(header_file_); - + if(cache.GetCount() > 2000) // 2000 cached headers is enough for everybody, right? cache.Clear();