From cbfd9dc16b41176ce5a79bd9e11a336e853573a0 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 17 Jun 2019 18:17:49 +0200 Subject: [PATCH] Clang: Update ModifiedTimeChecker in SymbolIndexer If a watched file changed we should update the ModifiedTimeChecker too. Change-Id: Ie43f5cf5b6dd4ddb1383168a1326add21f6e3e9d Reviewed-by: Tim Jenssen --- src/libs/clangsupport/modifiedtimechecker.h | 3 ++- src/libs/clangsupport/modifiedtimecheckerinterface.h | 1 + .../clangrefactoringbackend/source/symbolindexer.cpp | 6 ++++-- src/tools/clangrefactoringbackend/source/symbolindexer.h | 2 +- tests/unit/unittest/mockmodifiedtimechecker.h | 2 ++ tests/unit/unittest/symbolindexer-test.cpp | 9 +++++++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libs/clangsupport/modifiedtimechecker.h b/src/libs/clangsupport/modifiedtimechecker.h index c9b62c4673c..9247933b184 100644 --- a/src/libs/clangsupport/modifiedtimechecker.h +++ b/src/libs/clangsupport/modifiedtimechecker.h @@ -25,6 +25,7 @@ #pragma once +#include "clangpathwatcher.h" #include "filepathcachinginterface.h" #include "modifiedtimecheckerinterface.h" @@ -54,7 +55,7 @@ public: return compareEntries(sourceEntries); } - void pathsChanged(const FilePathIds &filePathIds) + void pathsChanged(const FilePathIds &filePathIds) override { using SourceTimeStampReferences = std::vector>; diff --git a/src/libs/clangsupport/modifiedtimecheckerinterface.h b/src/libs/clangsupport/modifiedtimecheckerinterface.h index a0e79b0701e..b48c38869e5 100644 --- a/src/libs/clangsupport/modifiedtimecheckerinterface.h +++ b/src/libs/clangsupport/modifiedtimecheckerinterface.h @@ -38,6 +38,7 @@ public: ModifiedTimeCheckerInterface &operator=(const ModifiedTimeCheckerInterface &) = delete; virtual bool isUpToDate(const SourceEntries &sourceEntries) const = 0; + virtual void pathsChanged(const FilePathIds &filePathIds) = 0; protected: ~ModifiedTimeCheckerInterface() = default; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 1ee61eb67c2..299088aa4b9 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -87,8 +87,8 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ void SymbolIndexer::updateProjectParts(ProjectPartContainers &&projectParts) { - for (ProjectPartContainer &projectPart : projectParts) - updateProjectPart(std::move(projectPart)); + for (ProjectPartContainer &projectPart : projectParts) + updateProjectPart(std::move(projectPart)); } void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) @@ -154,6 +154,8 @@ void SymbolIndexer::pathsWithIdsChanged(const ProjectPartIds &) {} void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds) { + m_modifiedTimeChecker.pathsChanged(filePathIds); + FilePathIds dependentSourcePathIds = m_symbolStorage.fetchDependentSourceIds(filePathIds); std::vector symbolIndexerTask; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h index 64b442bf33d..d969cd80264 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.h @@ -29,8 +29,8 @@ #include "symbolindexertaskqueueinterface.h" #include "symbolstorageinterface.h" #include "builddependenciesstorageinterface.h" -#include "clangpathwatcher.h" +#include #include #include #include diff --git a/tests/unit/unittest/mockmodifiedtimechecker.h b/tests/unit/unittest/mockmodifiedtimechecker.h index bf101988b16..1fa3dd497ca 100644 --- a/tests/unit/unittest/mockmodifiedtimechecker.h +++ b/tests/unit/unittest/mockmodifiedtimechecker.h @@ -35,6 +35,7 @@ class MockSourceEntriesModifiedTimeChecker public: MOCK_CONST_METHOD1(isUpToDate, bool (const ClangBackEnd::SourceEntries &sourceEntries)); + MOCK_METHOD1(pathsChanged, void(const ClangBackEnd::FilePathIds &filePathIds)); }; class MockSourceTimeStampsModifiedTimeChecker @@ -42,4 +43,5 @@ class MockSourceTimeStampsModifiedTimeChecker { public: MOCK_CONST_METHOD1(isUpToDate, bool(const ClangBackEnd::SourceTimeStamps &sourceTimeStamps)); + MOCK_METHOD1(pathsChanged, void(const ClangBackEnd::FilePathIds &filePathIds)); }; diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 0bfcf131880..c7831d099f2 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -1667,6 +1667,15 @@ TEST_F(SymbolIndexer, PathsChangedUpdatesFileStatusCache) ASSERT_THAT(fileStatusCache.lastModifiedTime(sourceId), 65); } +TEST_F(SymbolIndexer, PathsChangedCallsModifiedTimeChecker) +{ + auto sourceId = filePathId(TESTDATA_DIR "/symbolindexer_pathChanged.cpp"); + + EXPECT_CALL(mockModifiedTimeChecker, pathsChanged(ElementsAre(sourceId))); + + indexer.pathsChanged({sourceId}); +} + TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent) { ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A()))