forked from qt-creator/qt-creator
		
	CppLocatorFilter: Fix result sorting
* Fix rating items with startsWith()/contains() higher * Rate matches in function parameter list lower Task-number: QTCREATORBUG-19377 Change-Id: I2ea4c3ba96cd086aef82627326fa0888f700850f Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
		
				
					committed by
					
						
						André Hartmann
					
				
			
			
				
	
			
			
			
						parent
						
							a80396f807
						
					
				
				
					commit
					a59097086b
				
			@@ -70,6 +70,7 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future)
 | 
			
		||||
QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
 | 
			
		||||
        QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
 | 
			
		||||
{
 | 
			
		||||
    QList<Core::LocatorFilterEntry> normalEntries;
 | 
			
		||||
    QList<Core::LocatorFilterEntry> goodEntries;
 | 
			
		||||
    QList<Core::LocatorFilterEntry> betterEntries;
 | 
			
		||||
    QList<Core::LocatorFilterEntry> bestEntries;
 | 
			
		||||
@@ -91,9 +92,14 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
 | 
			
		||||
            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);
 | 
			
		||||
            bool matchInParameterList = false;
 | 
			
		||||
            if (!match.hasMatch() && (type == IndexItem::Function)) {
 | 
			
		||||
                matchString += info->symbolType();
 | 
			
		||||
                match = regexp.match(matchString);
 | 
			
		||||
                matchInParameterList = true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (match.hasMatch()) {
 | 
			
		||||
                Core::LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
 | 
			
		||||
 | 
			
		||||
@@ -109,9 +115,11 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
 | 
			
		||||
                        start -= matchOffset;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (matchString.startsWith(entry, caseSensitivityForPrefix))
 | 
			
		||||
                if (matchInParameterList)
 | 
			
		||||
                    normalEntries.append(filterEntry);
 | 
			
		||||
                else if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix))
 | 
			
		||||
                    bestEntries.append(filterEntry);
 | 
			
		||||
                else if (matchString.contains(entry, caseSensitivityForPrefix))
 | 
			
		||||
                else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix))
 | 
			
		||||
                    betterEntries.append(filterEntry);
 | 
			
		||||
                else
 | 
			
		||||
                    goodEntries.append(filterEntry);
 | 
			
		||||
@@ -124,6 +132,8 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
 | 
			
		||||
            return IndexItem::Recurse;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (normalEntries.size() < 1000)
 | 
			
		||||
        Utils::sort(normalEntries, Core::LocatorFilterEntry::compareLexigraphically);
 | 
			
		||||
    if (goodEntries.size() < 1000)
 | 
			
		||||
        Utils::sort(goodEntries, Core::LocatorFilterEntry::compareLexigraphically);
 | 
			
		||||
    if (betterEntries.size() < 1000)
 | 
			
		||||
@@ -133,6 +143,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
 | 
			
		||||
 | 
			
		||||
    bestEntries += betterEntries;
 | 
			
		||||
    bestEntries += goodEntries;
 | 
			
		||||
    bestEntries += normalEntries;
 | 
			
		||||
    return bestEntries;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -198,8 +198,9 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
 | 
			
		||||
        << _("pos")
 | 
			
		||||
        << (QList<ResultData>()
 | 
			
		||||
            << ResultData(_("positiveNumber()"), testFileShort)
 | 
			
		||||
            << ResultData(_("matchArgument(Pos)"), testFileShort)
 | 
			
		||||
            << ResultData(_("somePositionWithin()"), testFileShort)
 | 
			
		||||
            << ResultData(_("pointOfService()"), testFileShort)
 | 
			
		||||
            << ResultData(_("matchArgument(Pos)"), testFileShort)
 | 
			
		||||
           );
 | 
			
		||||
 | 
			
		||||
    QTest::newRow("CppFunctionsFilter-arguments")
 | 
			
		||||
@@ -238,12 +239,14 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
 | 
			
		||||
            << cppFunctionsFilter
 | 
			
		||||
            << _("MyClass::func")
 | 
			
		||||
            << (QList<ResultData>()
 | 
			
		||||
                << ResultData(_("functionDefinedInClass(bool, int)"), _("MyClass (file1.cpp)"))
 | 
			
		||||
                << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass (file1.cpp)"))
 | 
			
		||||
                << 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(_("functionDefinedOutSideClass(char)"),
 | 
			
		||||
                              _("MyClass (file1.cpp)"))
 | 
			
		||||
                << ResultData(_("functionDefinedOutSideClass(char)"),
 | 
			
		||||
                              _("MyNamespace::MyClass (file1.cpp)"))
 | 
			
		||||
                << ResultData(_("functionDefinedOutSideClass(char)"),
 | 
			
		||||
@@ -276,12 +279,6 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
 | 
			
		||||
        << cppLocatorFilter
 | 
			
		||||
        << _("my")
 | 
			
		||||
        << (QList<ResultData>()
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass"), testFileShort)
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass::MyClass"), _("()"))
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass::functionDefinedOutSideClass"),
 | 
			
		||||
                          _("(char)"))
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyEnum"), testFileShort)
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::myFunction"), _("(bool, int)"))
 | 
			
		||||
            << ResultData(_("MyClass"), testFileShort)
 | 
			
		||||
            << ResultData(_("MyClass::MyClass"), _("()"))
 | 
			
		||||
            << ResultData(_("MyClass::functionDefinedOutSideClass"), _("(char)"))
 | 
			
		||||
@@ -295,6 +292,12 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
 | 
			
		||||
            << ResultData(_("MyNamespace::MyEnum"), testFileShort)
 | 
			
		||||
            << ResultData(_("MyNamespace::myFunction"), _("(bool, int)"))
 | 
			
		||||
            << ResultData(_("myFunction"), _("(bool, int)"))
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass"), testFileShort)
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass::MyClass"), _("()"))
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyClass::functionDefinedOutSideClass"),
 | 
			
		||||
                          _("(char)"))
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::MyEnum"), testFileShort)
 | 
			
		||||
            << ResultData(_("<anonymous namespace>::myFunction"), _("(bool, int)"))
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
    QTest::newRow("CppClassesFilter-ObjC")
 | 
			
		||||
@@ -328,6 +331,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
 | 
			
		||||
        << ResultData(_("int myVariable"), _(""))
 | 
			
		||||
        << ResultData(_("myFunction(bool, int)"), _(""))
 | 
			
		||||
        << ResultData(_("Pos"), _(""))
 | 
			
		||||
        << ResultData(_("somePositionWithin()"), _(""))
 | 
			
		||||
        << ResultData(_("pointOfService()"), _(""))
 | 
			
		||||
        << ResultData(_("matchArgument(Pos)"), _(""))
 | 
			
		||||
        << ResultData(_("positiveNumber()"), _(""))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user