Commit bacfc28a authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

CppTools: Match also function arguments in locator

Useful when there are several overloads for the same function.

Change-Id: I325bda7d2fdf4108f71a61d5473cd55310c51c28
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 2d5d62fd
......@@ -83,8 +83,11 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
m_data->filterAllFiles([&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
if (future.isCanceled())
return IndexItem::Break;
if (info->type() & wanted) {
const IndexItem::ItemType type = info->type();
if (type & wanted) {
QString matchString = hasColonColon ? info->scopedSymbolName() : info->symbolName();
if (type == IndexItem::Function)
matchString += info->symbolType();
QRegularExpressionMatch match = regexp.match(matchString);
if (match.hasMatch()) {
Core::LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
......
......@@ -196,10 +196,26 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< _("pos")
<< (QList<ResultData>()
<< ResultData(_("positiveNumber()"), testFileShort)
<< ResultData(_("getPosition()"), testFileShort)
<< ResultData(_("matchArgument(Pos)"), testFileShort)
<< ResultData(_("pointOfService()"), testFileShort)
);
QTest::newRow("CppFunctionsFilter-arguments")
<< testFile
<< cppFunctionsFilter
<< _("function*bool")
<< (QList<ResultData>()
<< ResultData(_("functionDefinedInClass(bool, int)"),
_("MyClass (file1.cpp)"))
<< ResultData(_("functionDefinedInClass(bool, int)"),
_("MyNamespace::MyClass (file1.cpp)"))
<< ResultData(_("functionDefinedInClass(bool, int)"),
_("<anonymous namespace>::MyClass (file1.cpp)"))
<< ResultData(_("myFunction(bool, int)"), testFileShort)
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace (file1.cpp)"))
<< ResultData(_("myFunction(bool, int)"), _("<anonymous namespace> (file1.cpp)"))
);
QTest::newRow("CppFunctionsFilter-WithNamespacePrefix")
<< testFile
<< cppFunctionsFilter
......@@ -290,8 +306,9 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
QList<ResultData> expectedResults = QList<ResultData>()
<< ResultData(_("int myVariable"), _(""))
<< ResultData(_("myFunction(bool, int)"), _(""))
<< ResultData(_("Pos"), _(""))
<< ResultData(_("pointOfService()"), _(""))
<< ResultData(_("getPosition()"), _(""))
<< ResultData(_("matchArgument(Pos)"), _(""))
<< ResultData(_("positiveNumber()"), _(""))
<< ResultData(_("MyEnum"), _(""))
<< ResultData(_("int V1"), _("MyEnum"))
......
......@@ -12,8 +12,9 @@ int myVariable;
int myFunction(bool yesno, int number) {}
struct Pos {};
void pointOfService() {}
int getPosition() { return 0; }
int matchArgument(Pos p) { return 0; }
int positiveNumber() { return 2; }
enum MyEnum { V1, V2 };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment