From 414561e4ccdc1a4a110234848b338c7bb78c4df5 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 10 Aug 2020 18:10:28 +0200 Subject: CppTools: More consistent fuzzy matching behavior There were annoying inconsistencies, for instance: - A not fully matching declaration was found from the definition, but not vice versa. - An implementation MyClass::foo(int) would fall back to a declaration foo(), but an implementation MyClass::foo() would not fall back to a declaration foo(int). These cases behave consistently now. To this end, the clang code model now forwards to the built-in code model if a function lookup has failed. Fuzzy matching for free functions has been limited, as the cons appear to outweigh the pros. For instance: void foo(int); void foo(double) {} Following the definition would lead to the non-matching declaration, which the user most likely does not want. As a side effect, redundant code has been removed in the SymbolFinder class. Fixes: QTCREATORBUG-20279 Change-Id: Ib97d6710c7e12fb0fdbc30b51a0067e09bfc2190 Reviewed-by: Christian Stenger --- .../followsymbol_switchmethoddecldef_test.cpp | 76 ++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) (limited to 'src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp') diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 8bbb010422e..7532b77e8dc 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -935,6 +935,16 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data() "void Foo::foo(int) {}\n" ); + QTest::newRow("matchFunctionSignature_Follow_3.5") << _( + "void foo(int);\n" + "void @$foo() {}\n" + ); + + QTest::newRow("matchFunctionSignature_Follow_3.6") << _( + "void foo(int);\n" + "void @$foo(double) {}\n" + ); + QTest::newRow("matchFunctionSignature_Follow_4") << _( "class Foo {\n" " void foo(int);\n" @@ -963,17 +973,33 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data() "void Foo::@foo(int) {}\n" ); - QTest::newRow("matchFunctionSignature_Follow_8") << _( + QTest::newRow("matchFunctionSignature_Follow_8_fuzzy") << _( "class Foo {\n" - " void @$foo(int *);\n" + " void @foo(int *);\n" + "};\n" + "void Foo::$foo(const int *) {}\n" + ); + + QTest::newRow("matchFunctionSignature_Follow_8_exact") << _( + "class Foo {\n" + " void @foo(int *);\n" "};\n" "void Foo::foo(const int *) {}\n" + "void Foo::$foo(int *) {}\n" ); - QTest::newRow("matchFunctionSignature_Follow_9") << _( + QTest::newRow("matchFunctionSignature_Follow_9_fuzzy") << _( "class Foo {\n" - " void @$foo(int&);\n" + " void @foo(int&);\n" "};\n" + "void Foo::$foo(const int&) {}\n" + ); + + QTest::newRow("matchFunctionSignature_Follow_9_exact") << _( + "class Foo {\n" + " void @foo(int&);\n" + "};\n" + "void Foo::$foo(int&) {}\n" "void Foo::foo(const int&) {}\n" ); @@ -1171,6 +1197,48 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data() "foo.cpp") ); + QTest::newRow("matchFunctionSignatureFuzzy1Forward") << (QList() + << TestDocument::create("class Foo {\n" + " void @foo(int);\n" + " void foo();\n" + "};\n", + "foo.h") + << TestDocument::create("#include \"foo.h\"\n" + "void Foo::$foo() {}\n", + "foo.cpp") + ); + + QTest::newRow("matchFunctionSignatureFuzzy1Backward") << (QList() + << TestDocument::create("class Foo {\n" + " void $foo(int);\n" + "};\n", + "foo.h") + << TestDocument::create("#include \"foo.h\"\n" + "void Foo::@foo() {}\n", + "foo.cpp") + ); + + QTest::newRow("matchFunctionSignatureFuzzy2Forward") << (QList() + << TestDocument::create("class Foo {\n" + " void foo(int);\n" + " void @foo();\n" + "};\n", + "foo.h") + << TestDocument::create("#include \"foo.h\"\n" + "void Foo::$foo(int) {}\n", + "foo.cpp") + ); + + QTest::newRow("matchFunctionSignatureFuzzy2Backward") << (QList() + << TestDocument::create("class Foo {\n" + " void $foo();\n" + "};\n", + "foo.h") + << TestDocument::create("#include \"foo.h\"\n" + "void Foo::@foo(int) {}\n", + "foo.cpp") + ); + QTest::newRow("globalVar") << QList{ TestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"), TestDocument::create( -- cgit v1.2.3