logic: Fixed source files indexed multiple times when in multiple source groups

This commit is contained in:
Eberhard Graether
2017-05-30 12:17:18 +02:00
parent 561284ef5a
commit f760b873b4
7 changed files with 53 additions and 28 deletions
+5 -3
View File
@@ -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<FilePath>& filesToClean, bool fullRefresh, bool preprocessorOnly)
void Project::buildIndex(
const std::set<FilePath>& filesToIndex, const std::set<FilePath>& filesToClean, bool fullRefresh, bool preprocessorOnly)
{
MessageClearErrorCount().dispatch();
if (fullRefresh)
@@ -437,10 +438,11 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, bool fullRefres
));
}
std::set<FilePath> filesToIndexTemp = filesToIndex;
std::shared_ptr<IndexerCommandList> indexerCommandList = std::make_shared<IndexerCommandList>();
for (std::shared_ptr<SourceGroup> sourceGroup: m_sourceGroups)
{
for (std::shared_ptr<IndexerCommand> command: sourceGroup->getIndexerCommands(fullRefresh))
for (std::shared_ptr<IndexerCommand> command: sourceGroup->getIndexerCommands(&filesToIndexTemp, fullRefresh))
{
command->setPreprocessorOnly(preprocessorOnly);
indexerCommandList->addCommand(command);
+5 -1
View File
@@ -47,7 +47,11 @@ public: // todo: make private again
private:
bool requestIndex(bool forceRefresh, bool needsFullRefresh);
void buildIndex(const std::set<FilePath>& filesToClean, bool fullRefresh, bool preprocessorOnly);
void buildIndex(
const std::set<FilePath>& filesToIndex,
const std::set<FilePath>& filesToClean,
bool fullRefresh,
bool preprocessorOnly);
bool hasCxxSourceGroup() const;
+2 -1
View File
@@ -28,7 +28,8 @@ public:
std::set<FilePath> getAllSourceFilePaths() const;
std::set<FilePath> getSourceFilePathsToIndex() const;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const bool fullRefresh) = 0;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh) = 0;
protected:
std::set<FilePath> m_allSourceFilePaths;
+26 -17
View File
@@ -72,7 +72,8 @@ void SourceGroupCxx::fetchAllSourceFilePaths()
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(const bool fullRefresh)
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh)
{
std::shared_ptr<ApplicationSettings> appSettings = ApplicationSettings::getInstance();
@@ -125,10 +126,10 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(
}
}
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
FilePath cdbPath = m_settings->getCompilationDatabasePathExpandedAndAbsolute();
if (cdbPath.exists())
{
@@ -145,19 +146,20 @@ std::vector<std::shared_ptr<IndexerCommand>> 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<std::string> currentCompilerFlags = compilerFlags;
currentCompilerFlags.insert(currentCompilerFlags.end(), command.CommandLine.begin(), command.CommandLine.end());
indexerCommands.push_back(std::make_shared<IndexerCommandCxxCdb>(
FilePath(path),
sourcePath,
indexedPaths,
excludedPaths,
FilePath(command.Directory),
@@ -165,6 +167,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(
systemHeaderSearchPaths,
frameworkSearchPaths
));
filesToIndex->erase(sourcePath);
}
}
}
@@ -172,15 +176,20 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(
{
for (const FilePath& sourcePath: sourceFilePathsToIndex)
{
indexerCommands.push_back(std::make_shared<IndexerCommandCxxManual>(
sourcePath,
indexedPaths,
excludedPaths,
m_settings->getStandard(),
systemHeaderSearchPaths,
frameworkSearchPaths,
compilerFlags
));
if (filesToIndex->find(sourcePath) != filesToIndex->end())
{
indexerCommands.push_back(std::make_shared<IndexerCommandCxxManual>(
sourcePath,
indexedPaths,
excludedPaths,
m_settings->getStandard(),
systemHeaderSearchPaths,
frameworkSearchPaths,
compilerFlags
));
filesToIndex->erase(sourcePath);
}
}
}
+2 -1
View File
@@ -19,7 +19,8 @@ public:
virtual void fetchAllSourceFilePaths();
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const bool fullRefresh);
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh);
private:
std::shared_ptr<SourceGroupSettingsCxx> m_settings;
+11 -4
View File
@@ -71,7 +71,8 @@ void SourceGroupJava::fetchAllSourceFilePaths()
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(const bool fullRefresh)
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh)
{
std::vector<FilePath> classPath = getClassPath();
@@ -93,12 +94,18 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
}
}
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (const FilePath& sourcePath: sourceFilePathsToIndex)
{
indexerCommands.push_back(std::make_shared<IndexerCommandJava>(sourcePath, indexedPaths, excludedPaths, classPath));
if (filesToIndex->find(sourcePath) != filesToIndex->end())
{
indexerCommands.push_back(
std::make_shared<IndexerCommandJava>(sourcePath, indexedPaths, excludedPaths, classPath));
filesToIndex->erase(sourcePath);
}
}
return indexerCommands;
+2 -1
View File
@@ -19,7 +19,8 @@ public:
virtual void fetchAllSourceFilePaths();
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const bool fullRefresh);
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh);
private:
bool prepareJavaEnvironment();