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);
|
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)
|
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||||
|
@@ -33,6 +33,8 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<IndexItem::Ptr> findSymbols(IndexItem::ItemType type, const QString &symbolName) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
||||||
void onAboutToRemoveFiles(const QStringList &files);
|
void onAboutToRemoveFiles(const QStringList &files);
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppfunctiondecldeflink.h"
|
#include "cppfunctiondecldeflink.h"
|
||||||
#include "cppinsertvirtualmethods.h"
|
#include "cppinsertvirtualmethods.h"
|
||||||
|
#include "cpplocatordata.h"
|
||||||
#include "cpppointerdeclarationformatter.h"
|
#include "cpppointerdeclarationformatter.h"
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
#include "cppquickfixprojectsettings.h"
|
#include "cppquickfixprojectsettings.h"
|
||||||
@@ -1990,48 +1991,45 @@ Snapshot forwardingHeaders(const CppQuickFixInterface &interface)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchName(const Name *name, QList<Core::LocatorFilterEntry> *matches, QString *className) {
|
QList<IndexItem::Ptr> matchName(const Name *name, QString *className)
|
||||||
|
{
|
||||||
if (!name)
|
if (!name)
|
||||||
return false;
|
return {};
|
||||||
|
|
||||||
QString simpleName;
|
QString simpleName;
|
||||||
if (Core::ILocatorFilter *classesFilter = CppModelManager::instance()->classesFilter()) {
|
QList<IndexItem::Ptr> matches;
|
||||||
QFutureInterface<Core::LocatorFilterEntry> dummy;
|
CppLocatorData *locatorData = CppModelManager::instance()->locatorData();
|
||||||
|
const Overview oo;
|
||||||
const Overview oo;
|
if (const QualifiedNameId *qualifiedName = name->asQualifiedNameId()) {
|
||||||
if (const QualifiedNameId *qualifiedName = name->asQualifiedNameId()) {
|
const Name *name = qualifiedName->name();
|
||||||
const Name *name = qualifiedName->name();
|
if (const TemplateNameId *templateName = name->asTemplateNameId()) {
|
||||||
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()) {
|
|
||||||
*className = templateNameAsString(templateName);
|
*className = templateNameAsString(templateName);
|
||||||
} else {
|
} else {
|
||||||
*className = oo.prettyName(name);
|
simpleName = oo.prettyName(name);
|
||||||
}
|
|
||||||
|
|
||||||
if (matches->empty()) {
|
|
||||||
classesFilter->prepareSearch(*className);
|
|
||||||
*matches = classesFilter->matchesFor(dummy, *className);
|
|
||||||
}
|
|
||||||
if (matches->empty() && !simpleName.isEmpty())
|
|
||||||
*className = simpleName;
|
*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
|
} // anonymous namespace
|
||||||
@@ -2048,17 +2046,16 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QString className;
|
QString className;
|
||||||
QList<Core::LocatorFilterEntry> matches;
|
|
||||||
const QString currentDocumentFilePath = interface.semanticInfo().doc->filePath().toString();
|
const QString currentDocumentFilePath = interface.semanticInfo().doc->filePath().toString();
|
||||||
const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath);
|
const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath);
|
||||||
FilePaths headers;
|
FilePaths headers;
|
||||||
|
|
||||||
|
const QList<IndexItem::Ptr> matches = matchName(nameAst->name, &className);
|
||||||
// Find an include file through the locator
|
// Find an include file through the locator
|
||||||
if (matchName(nameAst->name, &matches, &className)) {
|
if (!matches.isEmpty()) {
|
||||||
QList<IndexItem::Ptr> indexItems;
|
QList<IndexItem::Ptr> indexItems;
|
||||||
const Snapshot forwardHeaders = forwardingHeaders(interface);
|
const Snapshot forwardHeaders = forwardingHeaders(interface);
|
||||||
for (const Core::LocatorFilterEntry &entry : std::as_const(matches)) {
|
for (const IndexItem::Ptr &info : matches) {
|
||||||
IndexItem::Ptr info = entry.internalData.value<IndexItem::Ptr>();
|
|
||||||
if (!info || info->symbolName() != className)
|
if (!info || info->symbolName() != className)
|
||||||
continue;
|
continue;
|
||||||
indexItems << info;
|
indexItems << info;
|
||||||
|
Reference in New Issue
Block a user