summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/symbolfinder.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-10-08 13:32:36 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-10-12 15:08:24 +0000
commit6b6ad446ebdff5709278e299f525dba6173f3427 (patch)
tree719a643bff78fb2522326ea0c2102cdba1db5d67 /src/plugins/cpptools/symbolfinder.cpp
parenteccc5676516f2ee22884cd9cbf15e6dba76fc632 (diff)
downloadqt-creator-6b6ad446ebdff5709278e299f525dba6173f3427.tar.gz
CppTools: Make FollowSymbol respect projects
Finding the class definition for a forward declaration or finding the function definition from its declaration is mostly determined by the file iteration order. Documents with the most common path prefix are checked first. This works fine as long as the files of your project have a common ancestor. If that's not the case, FollowSymbol might take you to the definition within another project. Fix that issue by considering the project part id when constructing the file iteration order. Since the cached file iteration order now depends on the projects, ensure to clear it if projects are added, changed or removed. Task-number: QTCREATORBUG-15116 Change-Id: I529166bac363959c9fee0b946747fd0370a88809 Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/symbolfinder.cpp')
-rw-r--r--src/plugins/cpptools/symbolfinder.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/plugins/cpptools/symbolfinder.cpp b/src/plugins/cpptools/symbolfinder.cpp
index 26df91bc04..3bc72c00b5 100644
--- a/src/plugins/cpptools/symbolfinder.cpp
+++ b/src/plugins/cpptools/symbolfinder.cpp
@@ -34,6 +34,8 @@
#include "symbolfinder.h"
+#include "cppmodelmanager.h"
+
#include <cplusplus/LookupContext.h>
#include <utils/qtcassert.h>
@@ -357,13 +359,20 @@ QStringList SymbolFinder::fileIterationOrder(const QString &referenceFile, const
insertCache(referenceFile, doc->fileName());
}
- QStringList files = m_filePriorityCache.value(referenceFile).values();
+ QStringList files = m_filePriorityCache.value(referenceFile).toStringList();
trackCacheUse(referenceFile);
return files;
}
+void SymbolFinder::clearCache()
+{
+ m_filePriorityCache.clear();
+ m_fileMetaCache.clear();
+ m_recent.clear();
+}
+
void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Snapshot &snapshot)
{
// We only check for "new" files, which which are in the snapshot but not in the cache.
@@ -376,18 +385,29 @@ void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Sna
}
}
+const QString projectPartIdForFile(const QString &filePath)
+{
+ const QList<ProjectPart::Ptr> parts = CppModelManager::instance()->projectPart(filePath);
+ if (!parts.isEmpty())
+ return parts.first()->id();
+ return QString();
+}
+
void SymbolFinder::clearCache(const QString &referenceFile, const QString &comparingFile)
{
- m_filePriorityCache[referenceFile].remove(computeKey(referenceFile, comparingFile),
- comparingFile);
+ m_filePriorityCache[referenceFile].remove(comparingFile, projectPartIdForFile(comparingFile));
m_fileMetaCache[referenceFile].remove(comparingFile);
}
void SymbolFinder::insertCache(const QString &referenceFile, const QString &comparingFile)
{
- // We want an ordering such that the documents with the most common path appear first.
- m_filePriorityCache[referenceFile].insert(computeKey(referenceFile, comparingFile),
- comparingFile);
+ FileIterationOrder &order = m_filePriorityCache[referenceFile];
+ if (!order.isValid()) {
+ const auto projectPartId = projectPartIdForFile(referenceFile);
+ order.setReference(referenceFile, projectPartId);
+ }
+ order.insert(comparingFile, projectPartIdForFile(comparingFile));
+
m_fileMetaCache[referenceFile].insert(comparingFile);
}
@@ -408,14 +428,3 @@ void SymbolFinder::trackCacheUse(const QString &referenceFile)
m_fileMetaCache.remove(oldest);
}
}
-
-int SymbolFinder::computeKey(const QString &referenceFile, const QString &comparingFile)
-{
- // As similar the path from the comparing file is to the path from the reference file,
- // the smaller the key is, which is then used for sorting the map.
- std::pair<QString::const_iterator,
- QString::const_iterator> r = std::mismatch(referenceFile.begin(),
- referenceFile.end(),
- comparingFile.begin());
- return referenceFile.length() - (r.first - referenceFile.begin());
-}