aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2017-10-31 08:25:12 +0200
committerOrgad Shaneh <orgads@gmail.com>2017-11-14 07:04:07 +0000
commitd2b8076fecc00f20e196c944e116865f85f79f2a (patch)
treeb19e011e384ab9f9f6d090d7aabd572f103fc58b /src
parent1a361a39ad6036bf961eabf94290c2b88ab19e3a (diff)
CppTools: Fix highlighting when matching with scope
class Foo { void funcInside() {} void funcOutside(); }; void Foo::funcOutside() {} Search for Foo::func in the locator. func was not highlighted. Change-Id: I923bd3ef2df47c5fa030b8899d1b4df7437b1820 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cpptools/cpplocatorfilter.cpp18
-rw-r--r--src/plugins/cpptools/cpplocatorfilter_test.cpp19
2 files changed, 33 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpplocatorfilter.cpp b/src/plugins/cpptools/cpplocatorfilter.cpp
index ba31251bf3..a2b94c2df1 100644
--- a/src/plugins/cpptools/cpplocatorfilter.cpp
+++ b/src/plugins/cpptools/cpplocatorfilter.cpp
@@ -73,19 +73,23 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
QList<Core::LocatorFilterEntry> betterEntries;
QList<Core::LocatorFilterEntry> bestEntries;
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
- bool hasColonColon = entry.contains(QLatin1String("::"));
const IndexItem::ItemType wanted = matchTypes();
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid())
return goodEntries;
+ const bool hasColonColon = entry.contains("::");
+ const QRegularExpression shortRegexp =
+ hasColonColon ? createRegExp(entry.mid(entry.lastIndexOf("::") + 2)) : regexp;
m_data->filterAllFiles([&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
if (future.isCanceled())
return IndexItem::Break;
const IndexItem::ItemType type = info->type();
if (type & wanted) {
- QString matchString = hasColonColon ? info->scopedSymbolName() : info->symbolName();
+ const QString symbolName = info->symbolName();
+ QString matchString = hasColonColon ? info->scopedSymbolName() : symbolName;
+ int matchOffset = hasColonColon ? matchString.size() - symbolName.size() : 0;
if (type == IndexItem::Function)
matchString += info->symbolType();
QRegularExpressionMatch match = regexp.match(matchString);
@@ -94,9 +98,15 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
// Highlight the matched characters, therefore it may be necessary
// to update the match if the displayName is different from matchString
- if (matchString != filterEntry.displayName)
- match = regexp.match(filterEntry.displayName);
+ if (matchString.midRef(matchOffset) != filterEntry.displayName) {
+ match = shortRegexp.match(filterEntry.displayName);
+ matchOffset = 0;
+ }
filterEntry.highlightInfo = highlightInfo(match);
+ if (matchOffset > 0) {
+ for (int &start : filterEntry.highlightInfo.starts)
+ start -= matchOffset;
+ }
if (matchString.startsWith(entry, caseSensitivityForPrefix))
bestEntries.append(filterEntry);
diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp
index 1b309fbe8a..b5cc9041b1 100644
--- a/src/plugins/cpptools/cpplocatorfilter_test.cpp
+++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp
@@ -231,6 +231,25 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace (file1.cpp)"))
);
+ QTest::newRow("CppFunctionsFilter-WithClassPrefix")
+ << testFile
+ << cppFunctionsFilter
+ << _("MyClass::func")
+ << (QList<ResultData>()
+ << ResultData(_("functionDefinedInClass(bool, int)"), _("MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedInClass(bool, int)"),
+ _("MyNamespace::MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedInClass(bool, int)"),
+ _("<anonymous namespace>::MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedOutSideClass(char)"),
+ _("MyNamespace::MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedOutSideClass(char)"),
+ _("<anonymous namespace>::MyClass (file1.cpp)"))
+ << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"),
+ _("MyNamespace::MyClass (file1.cpp)"))
+ );
+
QTest::newRow("CppClassesFilter")
<< testFile
<< cppClassesFilter