forked from qt-creator/qt-creator
CppLocatorData: Introduce findSymbols
Reuse it inside cppquickfixes.cpp. Don't use global CppModelManager::classesFilter, but more specialized and much faster CppLocatorData::findSymbols. The return value of CppLocatorData::findSymbols is a list of IndexItem::Ptr instead of LocatorFilterEntries, so that we may avoid using internalData for passing IndexItem::Ptr. Change-Id: I14591b3fcf4de34d6fea23b9f354fe898123c9af Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -20,6 +20,22 @@ CppLocatorData::CppLocatorData()
|
||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||
}
|
||||
|
||||
QList<IndexItem::Ptr> CppLocatorData::findSymbols(IndexItem::ItemType type,
|
||||
const QString &symbolName) const
|
||||
{
|
||||
QList<IndexItem::Ptr> matches;
|
||||
filterAllFiles([&](const IndexItem::Ptr &info) {
|
||||
if (info->type() & type) {
|
||||
if (info->symbolName() == symbolName || info->scopedSymbolName() == symbolName)
|
||||
matches << info;
|
||||
}
|
||||
if (info->type() & IndexItem::Enum)
|
||||
return IndexItem::Continue;
|
||||
return IndexItem::Recurse;
|
||||
});
|
||||
return matches;
|
||||
}
|
||||
|
||||
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
||||
{
|
||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||
|
@@ -33,6 +33,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
QList<IndexItem::Ptr> findSymbols(IndexItem::ItemType type, const QString &symbolName) const;
|
||||
|
||||
public slots:
|
||||
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
||||
void onAboutToRemoveFiles(const QStringList &files);
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "cppeditorwidget.h"
|
||||
#include "cppfunctiondecldeflink.h"
|
||||
#include "cppinsertvirtualmethods.h"
|
||||
#include "cpplocatordata.h"
|
||||
#include "cpppointerdeclarationformatter.h"
|
||||
#include "cppquickfixassistant.h"
|
||||
#include "cppquickfixprojectsettings.h"
|
||||
@@ -1990,48 +1991,45 @@ Snapshot forwardingHeaders(const CppQuickFixInterface &interface)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool matchName(const Name *name, QList<Core::LocatorFilterEntry> *matches, QString *className) {
|
||||
QList<IndexItem::Ptr> matchName(const Name *name, QString *className)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
return {};
|
||||
|
||||
QString simpleName;
|
||||
if (Core::ILocatorFilter *classesFilter = CppModelManager::instance()->classesFilter()) {
|
||||
QFutureInterface<Core::LocatorFilterEntry> dummy;
|
||||
|
||||
const Overview oo;
|
||||
if (const QualifiedNameId *qualifiedName = name->asQualifiedNameId()) {
|
||||
const Name *name = qualifiedName->name();
|
||||
if (const TemplateNameId *templateName = name->asTemplateNameId()) {
|
||||
*className = templateNameAsString(templateName);
|
||||
} else {
|
||||
simpleName = oo.prettyName(name);
|
||||
*className = simpleName;
|
||||
classesFilter->prepareSearch(*className);
|
||||
*matches = classesFilter->matchesFor(dummy, *className);
|
||||
if (matches->empty()) {
|
||||
if (const Name *name = qualifiedName->base()) {
|
||||
if (const TemplateNameId *templateName = name->asTemplateNameId())
|
||||
*className = templateNameAsString(templateName);
|
||||
else
|
||||
*className = oo.prettyName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const TemplateNameId *templateName = name->asTemplateNameId()) {
|
||||
QList<IndexItem::Ptr> matches;
|
||||
CppLocatorData *locatorData = CppModelManager::instance()->locatorData();
|
||||
const Overview oo;
|
||||
if (const QualifiedNameId *qualifiedName = name->asQualifiedNameId()) {
|
||||
const Name *name = qualifiedName->name();
|
||||
if (const TemplateNameId *templateName = name->asTemplateNameId()) {
|
||||
*className = templateNameAsString(templateName);
|
||||
} else {
|
||||
*className = oo.prettyName(name);
|
||||
}
|
||||
|
||||
if (matches->empty()) {
|
||||
classesFilter->prepareSearch(*className);
|
||||
*matches = classesFilter->matchesFor(dummy, *className);
|
||||
}
|
||||
if (matches->empty() && !simpleName.isEmpty())
|
||||
simpleName = oo.prettyName(name);
|
||||
*className = simpleName;
|
||||
matches = locatorData->findSymbols(IndexItem::Class, *className);
|
||||
if (matches.isEmpty()) {
|
||||
if (const Name *name = qualifiedName->base()) {
|
||||
if (const TemplateNameId *templateName = name->asTemplateNameId())
|
||||
*className = templateNameAsString(templateName);
|
||||
else
|
||||
*className = oo.prettyName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const TemplateNameId *templateName = name->asTemplateNameId()) {
|
||||
*className = templateNameAsString(templateName);
|
||||
} else {
|
||||
*className = oo.prettyName(name);
|
||||
}
|
||||
|
||||
return !matches->empty();
|
||||
if (matches.isEmpty())
|
||||
matches = locatorData->findSymbols(IndexItem::Class, *className);
|
||||
|
||||
if (matches.isEmpty() && !simpleName.isEmpty())
|
||||
*className = simpleName;
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@@ -2048,17 +2046,16 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
||||
return;
|
||||
|
||||
QString className;
|
||||
QList<Core::LocatorFilterEntry> matches;
|
||||
const QString currentDocumentFilePath = interface.semanticInfo().doc->filePath().toString();
|
||||
const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath);
|
||||
FilePaths headers;
|
||||
|
||||
const QList<IndexItem::Ptr> matches = matchName(nameAst->name, &className);
|
||||
// Find an include file through the locator
|
||||
if (matchName(nameAst->name, &matches, &className)) {
|
||||
if (!matches.isEmpty()) {
|
||||
QList<IndexItem::Ptr> indexItems;
|
||||
const Snapshot forwardHeaders = forwardingHeaders(interface);
|
||||
for (const Core::LocatorFilterEntry &entry : std::as_const(matches)) {
|
||||
IndexItem::Ptr info = entry.internalData.value<IndexItem::Ptr>();
|
||||
for (const IndexItem::Ptr &info : matches) {
|
||||
if (!info || info->symbolName() != className)
|
||||
continue;
|
||||
indexItems << info;
|
||||
|
Reference in New Issue
Block a user