Commit 8ad76164 authored by Marco Bubke's avatar Marco Bubke

Clang: Reparse for removed files too

Change-Id: Ibe8a3fa46bead6018a4279c3a270cb2535a7b296
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 053e9597
......@@ -68,7 +68,7 @@ void ClangFileSystemWatcher::addFiles(const QSet<Utf8String> &filePaths)
void ClangFileSystemWatcher::updateTranslationUnitsWithChangedDependencies(const QString &filePath)
{
translationUnits.updateTranslationUnitsWithChangedDependencies(filePath);
translationUnits.updateTranslationUnitsWithChangedDependency(filePath);
watcher.addPath(filePath);
emit fileChanged();
......
......@@ -62,7 +62,7 @@ void TranslationUnits::createOrUpdate(const QVector<FileContainer> &fileContaine
{
for (const FileContainer &fileContainer : fileContainers) {
createOrUpdateTranslationUnit(fileContainer);
updateTranslationUnitsWithChangedDependencies(fileContainer.filePath());
updateTranslationUnitsWithChangedDependency(fileContainer.filePath());
}
}
......@@ -82,17 +82,8 @@ void TranslationUnits::remove(const QVector<FileContainer> &fileContainers)
{
checkIfProjectPartsExists(fileContainers);
QVector<FileContainer> processedFileContainers = fileContainers;
auto removeBeginIterator = std::remove_if(translationUnits_.begin(), translationUnits_.end(), [&processedFileContainers] (const TranslationUnit &translationUnit) {
return removeFromFileContainer(processedFileContainers, translationUnit);
});
translationUnits_.erase(removeBeginIterator, translationUnits_.end());
if (!processedFileContainers.isEmpty())
throw TranslationUnitDoesNotExistException(processedFileContainers.first());
removeTranslationUnits(fileContainers);
updateTranslationUnitsWithChangedDependencies(fileContainers);
}
const TranslationUnit &TranslationUnits::translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const
......@@ -127,12 +118,18 @@ void TranslationUnits::addWatchedFiles(QSet<Utf8String> &filePaths)
fileSystemWatcher.addFiles(filePaths);
}
void TranslationUnits::updateTranslationUnitsWithChangedDependencies(const Utf8String &filePath)
void TranslationUnits::updateTranslationUnitsWithChangedDependency(const Utf8String &filePath)
{
for (auto &translationUnit : translationUnits_)
translationUnit.setDirtyIfDependencyIsMet(filePath);
}
void TranslationUnits::updateTranslationUnitsWithChangedDependencies(const QVector<FileContainer> &fileContainers)
{
for (const FileContainer &fileContainer : fileContainers)
updateTranslationUnitsWithChangedDependency(fileContainer.filePath());
}
void TranslationUnits::sendChangedDiagnostics()
{
for (const auto &translationUnit : translationUnits_) {
......@@ -228,5 +225,19 @@ void TranslationUnits::sendDiagnosticChangedMessage(const TranslationUnit &trans
}
}
void TranslationUnits::removeTranslationUnits(const QVector<FileContainer> &fileContainers)
{
QVector<FileContainer> processedFileContainers = fileContainers;
auto removeBeginIterator = std::remove_if(translationUnits_.begin(), translationUnits_.end(), [&processedFileContainers] (const TranslationUnit &translationUnit) {
return removeFromFileContainer(processedFileContainers, translationUnit);
});
translationUnits_.erase(removeBeginIterator, translationUnits_.end());
if (!processedFileContainers.isEmpty())
throw TranslationUnitDoesNotExistException(processedFileContainers.first());
}
} // namespace ClangBackEnd
......@@ -63,7 +63,8 @@ public:
void addWatchedFiles(QSet<Utf8String> &filePaths);
void updateTranslationUnitsWithChangedDependencies(const Utf8String &filePath);
void updateTranslationUnitsWithChangedDependency(const Utf8String &filePath);
void updateTranslationUnitsWithChangedDependencies(const QVector<FileContainer> &fileContainers);
void sendChangedDiagnostics();
......@@ -80,6 +81,7 @@ private:
void checkIfProjectPartExists(const Utf8String &projectFileName) const;
void checkIfProjectPartsExists(const QVector<FileContainer> &fileContainers) const;
void sendDiagnosticChangedMessage(const TranslationUnit &translationUnit);
void removeTranslationUnits(const QVector<FileContainer> &fileContainers);
private:
ClangFileSystemWatcher fileSystemWatcher;
......
......@@ -28,6 +28,7 @@
**
****************************************************************************/
#include <diagnosticset.h>
#include <filecontainer.h>
#include <projectpartcontainer.h>
#include <projectpart.h>
......@@ -149,6 +150,32 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse)
ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).isNeedingReparse());
}
TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
translationUnits.createOrUpdate({fileContainer, headerContainer});
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
translationUnits.createOrUpdate({headerContainerWithUnsavedContent});
ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewDiagnostics());
}
TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
translationUnits.createOrUpdate({fileContainer, headerContainer});
translationUnits.translationUnit(filePath, projectPartId).diagnostics();
translationUnits.remove({headerContainerWithUnsavedContent});
ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewDiagnostics());
}
TEST_F(TranslationUnits, DontGetNewerFileContainerIfRevisionIsTheSame)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment