ClangCodeModel: Do not mark the LHS of assignments as output parameters

... when using clangd. Amends a1f088376a.

Change-Id: Ief442d978e1cf3027dcba5a3c75b66c0f4ae8809
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-11-03 18:20:13 +01:00
parent 416cd69a5e
commit 33b5fa25a8
3 changed files with 32 additions and 3 deletions

View File

@@ -2404,16 +2404,37 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
return true;
if (token.type != "variable" && token.type != "property" && token.type != "parameter")
return false;
const QList<AstNode> path = getAstPath(ast, tokenRange(token));
const Range range = tokenRange(token);
const QList<AstNode> path = getAstPath(ast, range);
if (path.size() < 2)
return false;
if (path.last().hasConstType())
return false;
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|| it->kind() == "MemberInitializer" || it->kind() == "CXXOperatorCall") {
|| it->kind() == "MemberInitializer") {
return true;
}
// The token should get marked for e.g. lambdas, but not for assignment operators,
// where the user sees that it's being written.
if (it->kind() == "CXXOperatorCall") {
const QList<AstNode> children = it->children().value_or(QList<AstNode>());
if (children.size() < 2)
return false;
if (!children.last().range().contains(range))
return false;
QList<AstNode> firstChildTree{children.first()};
while (!firstChildTree.isEmpty()) {
const AstNode n = firstChildTree.takeFirst();
const QString detail = n.detail().value_or(QString());
if (detail.startsWith("operator"))
return !detail.contains('=');
firstChildTree << n.children().value_or(QList<AstNode>());
}
return true;
}
if (it->kind().endsWith("Cast") && it->hasConstType())
return false;
if (it->kind() == "Member" && it->arcanaContains("(")

View File

@@ -1040,7 +1040,9 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_PARAMETER, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("typedef as underlying type in enum declaration") << 424 << 21 << 424 << 39
<< QList<int>{C_TYPE} << 0;
QTest::newRow("argument to user-defined subscript operator") << 434 << 12 << 434 << 17
QTest::newRow("argument 1 to user-defined subscript operator") << 434 << 5 << 434 << 11
<< QList<int>{C_PARAMETER} << 0;
QTest::newRow("argument 2 to user-defined subscript operator") << 434 << 12 << 434 << 17
<< QList<int>{C_PARAMETER, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("partial class template specialization") << 553 << 25 << 553 << 28
<< QList<int>{C_TYPE, C_DECLARATION} << 0;
@@ -1246,6 +1248,7 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("const argument to unnamed lambda") << 830 << 16 << 830 << 19
<< QList<int>{C_LOCAL} << 0;
QTest::newRow("simple assignment") << 835 << 5 << 835 << 6 << QList<int>{C_LOCAL} << 0;
}
void ClangdTestHighlighting::test()

View File

@@ -829,3 +829,8 @@ void lambdaArgTest()
[](int &) {}(val);
[](int) {}(val);
}
void assignmentTest() {
struct S {} s;
s = {};
}