forked from qt-creator/qt-creator
Clang: Extend ClangPathWatcher to communicate path changes
Change-Id: Iad2d6adc53fbc2ee32fd63b9ccdc8999d41a89da Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -41,25 +41,30 @@ public:
|
||||
int id;
|
||||
FilePathId pathId;
|
||||
|
||||
friend bool operator==(const WatcherEntry &first, const WatcherEntry &second)
|
||||
friend bool operator==(WatcherEntry first, WatcherEntry second)
|
||||
{
|
||||
return first.id == second.id && first.pathId == second.pathId;
|
||||
}
|
||||
|
||||
friend bool operator<(const WatcherEntry &first, const WatcherEntry &second)
|
||||
friend bool operator<(WatcherEntry first, WatcherEntry second)
|
||||
{
|
||||
return std::tie(first.pathId, first.id) < std::tie(second.pathId, second.id);
|
||||
}
|
||||
|
||||
friend bool operator<(const WatcherEntry &entry, FilePathId pathId)
|
||||
friend bool operator<(WatcherEntry entry, FilePathId pathId)
|
||||
{
|
||||
return entry.pathId < pathId;
|
||||
}
|
||||
|
||||
friend bool operator<(FilePathId pathId, const WatcherEntry &entry)
|
||||
friend bool operator<(FilePathId pathId, WatcherEntry entry)
|
||||
{
|
||||
return pathId < entry.pathId;
|
||||
}
|
||||
|
||||
operator FilePathId() const
|
||||
{
|
||||
return pathId;
|
||||
}
|
||||
};
|
||||
|
||||
using WatcherEntries = std::vector<WatcherEntry>;
|
||||
@@ -224,7 +229,7 @@ unittest_public:
|
||||
std::transform(watcherEntries.begin(),
|
||||
watcherEntries.end(),
|
||||
std::back_inserter(paths),
|
||||
[&] (const WatcherEntry &entry) {
|
||||
[&] (WatcherEntry entry) {
|
||||
return QString(m_pathCache.filePath(entry.pathId).path());
|
||||
});
|
||||
|
||||
@@ -233,7 +238,7 @@ unittest_public:
|
||||
|
||||
template <typename Compare>
|
||||
WatcherEntries notWatchedEntries(const WatcherEntries &entries,
|
||||
Compare compare) const
|
||||
Compare compare) const
|
||||
{
|
||||
WatcherEntries notWatchedEntries;
|
||||
notWatchedEntries.reserve(entries.size());
|
||||
@@ -255,7 +260,7 @@ unittest_public:
|
||||
|
||||
WatcherEntries notWatchedPaths(const WatcherEntries &entries) const
|
||||
{
|
||||
auto compare = [] (const WatcherEntry &first, const WatcherEntry &second) {
|
||||
auto compare = [] (WatcherEntry first, WatcherEntry second) {
|
||||
return first.pathId < second.pathId;
|
||||
};
|
||||
|
||||
@@ -317,7 +322,7 @@ unittest_public:
|
||||
WatcherEntries uniqueEntries;
|
||||
uniqueEntries.reserve(pathEntries.size());
|
||||
|
||||
auto compare = [] (const WatcherEntry &first, const WatcherEntry &second) {
|
||||
auto compare = [] (WatcherEntry first, WatcherEntry second) {
|
||||
return first.pathId == second.pathId;
|
||||
};
|
||||
|
||||
@@ -342,7 +347,7 @@ unittest_public:
|
||||
WatcherEntries removeIdsFromWatchedEntries(const std::vector<int> &ids)
|
||||
{
|
||||
|
||||
auto keep = [&] (const WatcherEntry &entry) {
|
||||
auto keep = [&] (WatcherEntry entry) {
|
||||
return !std::binary_search(ids.begin(), ids.end(), entry.id);
|
||||
};
|
||||
|
||||
@@ -390,6 +395,20 @@ unittest_public:
|
||||
return foundEntries;
|
||||
}
|
||||
|
||||
FilePathIds watchedPaths(const FilePathIds &filePathIds) const
|
||||
{
|
||||
FilePathIds watchedFilePathIds;
|
||||
watchedFilePathIds.reserve(filePathIds.size());
|
||||
|
||||
std::set_intersection(m_watchedEntries.begin(),
|
||||
m_watchedEntries.end(),
|
||||
filePathIds.begin(),
|
||||
filePathIds.end(),
|
||||
std::back_inserter(watchedFilePathIds));
|
||||
|
||||
return watchedFilePathIds;
|
||||
}
|
||||
|
||||
Utils::SmallStringVector idsForWatcherEntries(const WatcherEntries &foundEntries)
|
||||
{
|
||||
Utils::SmallStringVector ids;
|
||||
@@ -398,7 +417,7 @@ unittest_public:
|
||||
std::transform(foundEntries.begin(),
|
||||
foundEntries.end(),
|
||||
std::back_inserter(ids),
|
||||
[&] (const WatcherEntry &entry) {
|
||||
[&] (WatcherEntry entry) {
|
||||
return Utils::SmallString(m_idCache.string(entry.id));
|
||||
});
|
||||
|
||||
@@ -414,7 +433,7 @@ unittest_public:
|
||||
return std::move(ids);
|
||||
}
|
||||
|
||||
void addChangedPathForFilePath(ClangBackEnd::FilePathIds &&filePathIds)
|
||||
void addChangedPathForFilePath(FilePathIds &&filePathIds)
|
||||
{
|
||||
if (m_notifier) {
|
||||
WatcherEntries foundEntries = watchedEntriesForPaths(std::move(filePathIds));
|
||||
@@ -422,6 +441,7 @@ unittest_public:
|
||||
Utils::SmallStringVector changedIds = idsForWatcherEntries(foundEntries);
|
||||
|
||||
m_notifier->pathsWithIdsChanged(uniqueIds(std::move(changedIds)));
|
||||
m_notifier->pathsChanged(watchedPaths(filePathIds));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user