forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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:
|
||||
|
@@ -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;
|
||||
|
@@ -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 "
|
||||
|
@@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user