src: Fixed FileRegisterStateData synchronisation

This commit is contained in:
Eberhard Graether
2017-04-12 00:38:48 +02:00
parent b9d1f5367c
commit 0e4b606c7c
4 changed files with 16 additions and 26 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ FileRegister::~FileRegister()
{ {
} }
FileRegisterStateData FileRegister::getStateData() const const FileRegisterStateData& FileRegister::getStateData() const
{ {
return m_stateData; return m_stateData;
} }
+1 -1
View File
@@ -12,7 +12,7 @@ public:
FileRegister(const FileRegisterStateData& stateData, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths); FileRegister(const FileRegisterStateData& stateData, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths);
virtual ~FileRegister(); virtual ~FileRegister();
FileRegisterStateData getStateData() const; const FileRegisterStateData& getStateData() const;
void markFileIndexing(const FilePath& filePath); void markFileIndexing(const FilePath& filePath);
void markIndexingFilesIndexed(); void markIndexingFilesIndexed();
+2 -10
View File
@@ -25,21 +25,13 @@ void FileRegisterStateData::inject(const FileRegisterStateData& o)
void FileRegisterStateData::markFileIndexing(const FilePath& filePath) void FileRegisterStateData::markFileIndexing(const FilePath& filePath)
{ {
std::lock_guard<std::mutex> lock(m_filePathsMutex); std::lock_guard<std::mutex> lock(m_filePathsMutex);
auto it = m_filePaths.find(filePath); m_filePaths[filePath] = STATE_INDEXING;
if (it != m_filePaths.end())
{
it->second = STATE_INDEXING;
}
else
{
m_filePaths.insert(std::make_pair(filePath, STATE_INDEXING));
}
} }
void FileRegisterStateData::markIndexingFilesIndexed() void FileRegisterStateData::markIndexingFilesIndexed()
{ {
std::lock_guard<std::mutex> lock(m_filePathsMutex); std::lock_guard<std::mutex> lock(m_filePathsMutex);
for (auto it: m_filePaths) for (auto& it: m_filePaths)
{ {
if (it.second == STATE_INDEXING) if (it.second == STATE_INDEXING)
{ {
@@ -22,6 +22,8 @@ PreprocessorCallbacks::PreprocessorCallbacks(
void PreprocessorCallbacks::FileChanged( void PreprocessorCallbacks::FileChanged(
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID prevID) clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID prevID)
{ {
m_currentPath = FilePath();
FilePath filePath; FilePath filePath;
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location)); const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
@@ -30,23 +32,19 @@ void PreprocessorCallbacks::FileChanged(
filePath = FilePath(fileEntry->getName()).canonical(); filePath = FilePath(fileEntry->getName()).canonical();
} }
const bool fileIsInProject = m_fileRegister->hasFilePath(filePath); if (!filePath.empty() && m_fileRegister->hasFilePath(filePath))
if (!filePath.empty() && fileIsInProject)
{ {
m_client->onFileParsed(FileSystem::getFileInfoForPath(filePath)); // todo: fix for tests m_client->onFileParsed(FileSystem::getFileInfoForPath(filePath)); // todo: fix for tests
if (reason == EnterFile && !m_fileRegister->fileIsIndexed(filePath))
{
m_fileRegister->markFileIndexing(filePath);
}
}
if (!filePath.empty() && fileIsInProject && !m_fileRegister->fileIsIndexed(filePath)) if (!m_fileRegister->fileIsIndexed(filePath))
{ {
m_currentPath = filePath; m_currentPath = filePath;
}
else if (reason == EnterFile)
{ {
m_currentPath = FilePath(); m_fileRegister->markFileIndexing(filePath);
}
}
} }
} }