diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-02-28 17:00:27 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-03-01 10:14:32 +0000 |
commit | 8247f4f3ddb2a33588c747dd16461fa074b7423e (patch) | |
tree | 7be0e3b618c1fa09f27fc3c8138146e38bbfd16f | |
parent | c5187da4abf823fdb7d07f780f24c3235b9c2c49 (diff) |
ClangCodeModel: Do not highlight objects in method calls
... as output arguments with clangd.
We might want to do so in the future, but right now it's not intended.
Task-number: QTCREATORBUG-27111
Change-Id: Ie6941f18943a1d6942901c526c62999cba6c1125
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
4 files changed, 40 insertions, 0 deletions
diff --git a/src/libs/languageserverprotocol/lsptypes.h b/src/libs/languageserverprotocol/lsptypes.h index 7bd004ca6cc..41e7459e011 100644 --- a/src/libs/languageserverprotocol/lsptypes.h +++ b/src/libs/languageserverprotocol/lsptypes.h @@ -141,6 +141,12 @@ public: { return JsonObject::contains(startKey) && JsonObject::contains(endKey); } }; +inline bool operator==(const Range &r1, const Range &r2) +{ + return r1.contains(r2) && r2.contains(r1); +} +inline bool operator!=(const Range &r1, const Range &r2) { return !(r1 == r2); } + class LANGUAGESERVERPROTOCOL_EXPORT Location : public JsonObject { public: diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 0cd258ba210..1ee1fe3d514 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -2723,6 +2723,19 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future, return false; if (it->hasConstType()) return false; + + if (it->kind() == "CXXMemberCall") { + if (it == path.rbegin()) + return false; + const QList<AstNode> children = it->children().value_or(QList<AstNode>()); + QTC_ASSERT(!children.isEmpty(), return false); + + // The called object is never displayed as an output parameter. + // TODO: A good argument can be made to display objects on which a non-const + // operator or function is called as output parameters. + return (it - 1)->range() != children.first().range(); + } + if (it->kind() == "Member" && it->arcanaContains("(") && !it->arcanaContains("bound member function type")) { return false; diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index 462b91f5092..dd5b95a63c7 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -1310,6 +1310,7 @@ void ClangdTestHighlighting::test_data() << QList<int>{C_PREPROCESSOR} << 0; QTest::newRow("deref operator (object)") << 960 << 10 << 960 << 11 << QList<int>{C_LOCAL} << 0; QTest::newRow("deref operator (member)") << 960 << 12 << 960 << 13 << QList<int>{C_FIELD} << 0; + QTest::newRow("nested call") << 979 << 20 << 979 << 21 << QList<int>{C_LOCAL} << 0; } void ClangdTestHighlighting::test() @@ -1397,6 +1398,8 @@ void ClangdTestHighlighting::test() QEXPECT_FAIL("non-final virtual function call via pointer", "clangd < 14 does not send virtual modifier", Continue); } + QEXPECT_FAIL("non-const reference via member function call as output argument (object)", + "See below", Continue); QEXPECT_FAIL("non-const reference via member function call as output argument (function)", "Without punctuation and comment tokens from clangd, it's not possible " "to highlight entire expressions. But do we really want this? What about nested " diff --git a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp index 31ddb82a00c..7275ddd3307 100644 --- a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp +++ b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp @@ -960,3 +960,21 @@ void derefOperator() if (*s.s) return; } + +struct my_struct +{ + void* method(int dummy); +}; + +my_struct* get_my_struct(); + +struct my_struct2 +{ + my_struct2(void* p); +}; + +void nestedCall() +{ + my_struct* s = get_my_struct(); + new my_struct2(s->method(0)); +} |