From f760b873b4144837ce509880968f1ae45c43764b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 30 May 2017 12:17:18 +0200 Subject: [PATCH] logic: Fixed source files indexed multiple times when in multiple source groups --- src/lib/project/Project.cpp | 8 +++-- src/lib/project/Project.h | 6 +++- src/lib/project/SourceGroup.h | 3 +- src/lib_cxx/project/SourceGroupCxx.cpp | 43 ++++++++++++++---------- src/lib_cxx/project/SourceGroupCxx.h | 3 +- src/lib_java/project/SourceGroupJava.cpp | 15 ++++++--- src/lib_java/project/SourceGroupJava.h | 3 +- 7 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index e6a78725..22d27cfb 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -411,12 +411,13 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) MessageStatus((fullRefresh ? "Reindexing Project" : "Refreshing Project"), false, true).dispatch(); - buildIndex(filesToClean, fullRefresh, preprocessorOnly); + buildIndex(filesToIndex, filesToClean, fullRefresh, preprocessorOnly); return true; } -void Project::buildIndex(const std::set& filesToClean, bool fullRefresh, bool preprocessorOnly) +void Project::buildIndex( + const std::set& filesToIndex, const std::set& filesToClean, bool fullRefresh, bool preprocessorOnly) { MessageClearErrorCount().dispatch(); if (fullRefresh) @@ -437,10 +438,11 @@ void Project::buildIndex(const std::set& filesToClean, bool fullRefres )); } + std::set filesToIndexTemp = filesToIndex; std::shared_ptr indexerCommandList = std::make_shared(); for (std::shared_ptr sourceGroup: m_sourceGroups) { - for (std::shared_ptr command: sourceGroup->getIndexerCommands(fullRefresh)) + for (std::shared_ptr command: sourceGroup->getIndexerCommands(&filesToIndexTemp, fullRefresh)) { command->setPreprocessorOnly(preprocessorOnly); indexerCommandList->addCommand(command); diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index ca61b39b..27ffaebc 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -47,7 +47,11 @@ public: // todo: make private again private: bool requestIndex(bool forceRefresh, bool needsFullRefresh); - void buildIndex(const std::set& filesToClean, bool fullRefresh, bool preprocessorOnly); + void buildIndex( + const std::set& filesToIndex, + const std::set& filesToClean, + bool fullRefresh, + bool preprocessorOnly); bool hasCxxSourceGroup() const; diff --git a/src/lib/project/SourceGroup.h b/src/lib/project/SourceGroup.h index 2156f859..1ced05aa 100644 --- a/src/lib/project/SourceGroup.h +++ b/src/lib/project/SourceGroup.h @@ -28,7 +28,8 @@ public: std::set getAllSourceFilePaths() const; std::set getSourceFilePathsToIndex() const; - virtual std::vector> getIndexerCommands(const bool fullRefresh) = 0; + virtual std::vector> getIndexerCommands( + std::set* filesToIndex, bool fullRefresh) = 0; protected: std::set m_allSourceFilePaths; diff --git a/src/lib_cxx/project/SourceGroupCxx.cpp b/src/lib_cxx/project/SourceGroupCxx.cpp index 15d8703a..698ad043 100644 --- a/src/lib_cxx/project/SourceGroupCxx.cpp +++ b/src/lib_cxx/project/SourceGroupCxx.cpp @@ -72,7 +72,8 @@ void SourceGroupCxx::fetchAllSourceFilePaths() m_allSourceFilePaths = fileManager.getAllSourceFilePaths(); } -std::vector> SourceGroupCxx::getIndexerCommands(const bool fullRefresh) +std::vector> SourceGroupCxx::getIndexerCommands( + std::set* filesToIndex, bool fullRefresh) { std::shared_ptr appSettings = ApplicationSettings::getInstance(); @@ -125,10 +126,10 @@ std::vector> SourceGroupCxx::getIndexerCommands( } } - std::vector> indexerCommands; - const std::set& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex()); + std::vector> indexerCommands; + FilePath cdbPath = m_settings->getCompilationDatabasePathExpandedAndAbsolute(); if (cdbPath.exists()) { @@ -145,19 +146,20 @@ std::vector> SourceGroupCxx::getIndexerCommands( for (clang::tooling::CompileCommand command: cdb->getAllCompileCommands()) { - FilePath path = FilePath(command.Filename).canonical(); - if (!path.isAbsolute()) + FilePath sourcePath = FilePath(command.Filename).canonical(); + if (!sourcePath.isAbsolute()) { - path = FilePath(command.Directory + '/' + command.Filename).canonical(); + sourcePath = FilePath(command.Directory + '/' + command.Filename).canonical(); } - if (sourceFilePathsToIndex.find(path) != sourceFilePathsToIndex.end()) + if (filesToIndex->find(sourcePath) != filesToIndex->end() && + sourceFilePathsToIndex.find(sourcePath) != sourceFilePathsToIndex.end()) { std::vector currentCompilerFlags = compilerFlags; currentCompilerFlags.insert(currentCompilerFlags.end(), command.CommandLine.begin(), command.CommandLine.end()); indexerCommands.push_back(std::make_shared( - FilePath(path), + sourcePath, indexedPaths, excludedPaths, FilePath(command.Directory), @@ -165,6 +167,8 @@ std::vector> SourceGroupCxx::getIndexerCommands( systemHeaderSearchPaths, frameworkSearchPaths )); + + filesToIndex->erase(sourcePath); } } } @@ -172,15 +176,20 @@ std::vector> SourceGroupCxx::getIndexerCommands( { for (const FilePath& sourcePath: sourceFilePathsToIndex) { - indexerCommands.push_back(std::make_shared( - sourcePath, - indexedPaths, - excludedPaths, - m_settings->getStandard(), - systemHeaderSearchPaths, - frameworkSearchPaths, - compilerFlags - )); + if (filesToIndex->find(sourcePath) != filesToIndex->end()) + { + indexerCommands.push_back(std::make_shared( + sourcePath, + indexedPaths, + excludedPaths, + m_settings->getStandard(), + systemHeaderSearchPaths, + frameworkSearchPaths, + compilerFlags + )); + + filesToIndex->erase(sourcePath); + } } } diff --git a/src/lib_cxx/project/SourceGroupCxx.h b/src/lib_cxx/project/SourceGroupCxx.h index 8b7ad778..ff40b879 100644 --- a/src/lib_cxx/project/SourceGroupCxx.h +++ b/src/lib_cxx/project/SourceGroupCxx.h @@ -19,7 +19,8 @@ public: virtual void fetchAllSourceFilePaths(); - virtual std::vector> getIndexerCommands(const bool fullRefresh); + virtual std::vector> getIndexerCommands( + std::set* filesToIndex, bool fullRefresh); private: std::shared_ptr m_settings; diff --git a/src/lib_java/project/SourceGroupJava.cpp b/src/lib_java/project/SourceGroupJava.cpp index 82863f03..340761dc 100644 --- a/src/lib_java/project/SourceGroupJava.cpp +++ b/src/lib_java/project/SourceGroupJava.cpp @@ -71,7 +71,8 @@ void SourceGroupJava::fetchAllSourceFilePaths() m_allSourceFilePaths = fileManager.getAllSourceFilePaths(); } -std::vector> SourceGroupJava::getIndexerCommands(const bool fullRefresh) +std::vector> SourceGroupJava::getIndexerCommands( + std::set* filesToIndex, bool fullRefresh) { std::vector classPath = getClassPath(); @@ -93,12 +94,18 @@ std::vector> SourceGroupJava::getIndexerCommands } } - std::vector> indexerCommands; - const std::set& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex()); + + std::vector> indexerCommands; for (const FilePath& sourcePath: sourceFilePathsToIndex) { - indexerCommands.push_back(std::make_shared(sourcePath, indexedPaths, excludedPaths, classPath)); + if (filesToIndex->find(sourcePath) != filesToIndex->end()) + { + indexerCommands.push_back( + std::make_shared(sourcePath, indexedPaths, excludedPaths, classPath)); + + filesToIndex->erase(sourcePath); + } } return indexerCommands; diff --git a/src/lib_java/project/SourceGroupJava.h b/src/lib_java/project/SourceGroupJava.h index 675f82da..469cedbb 100644 --- a/src/lib_java/project/SourceGroupJava.h +++ b/src/lib_java/project/SourceGroupJava.h @@ -19,7 +19,8 @@ public: virtual void fetchAllSourceFilePaths(); - virtual std::vector> getIndexerCommands(const bool fullRefresh); + virtual std::vector> getIndexerCommands( + std::set* filesToIndex, bool fullRefresh); private: bool prepareJavaEnvironment();