aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/cppquickfixes.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2023-03-20 18:02:05 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2023-04-04 07:50:10 +0000
commit16b9539a40c4ca8b49014136a89344a1fe7537c4 (patch)
tree7efb806acd0d3696d23e7b5928e81004b5638c30 /src/plugins/cppeditor/cppquickfixes.cpp
parent432d8e6e63251cb4d479f65f57ec5face91c9351 (diff)
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>
Diffstat (limited to 'src/plugins/cppeditor/cppquickfixes.cpp')
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp73
1 files changed, 35 insertions, 38 deletions
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 24e62a65d2..dad99ff134 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -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;