diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-11-09 11:54:44 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-11-10 09:04:52 +0000 |
commit | 397cbd77ab0080d42e5bb7cc99c12c5c3edc3b5c (patch) | |
tree | 6a001f8a5b0211c181fb0e450ae80d4887cb2a71 | |
parent | 401219bb07c8321492683d76450b64d1041f9d39 (diff) |
ClangCodeModel: Fix highlighting problem with template types
With clangd, we mis-detected variables of template types as output
parameters in certain contexts.
Change-Id: I906abd489f987351793f4ef676e4af59cdfdbf97
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/clangcodemodel/clangdclient.cpp | 10 | ||||
-rw-r--r-- | src/plugins/clangcodemodel/test/clangdtests.cpp | 1 | ||||
-rw-r--r-- | src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp | 6 |
3 files changed, 17 insertions, 0 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 09f9cedd19..fddf22e009 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -252,6 +252,16 @@ public: QString theType = type(); if (theType.endsWith("const")) theType.chop(5); + + // We don't care about the "inner" type of templates. + const int openAngleBracketPos = theType.indexOf('<'); + if (openAngleBracketPos != -1) { + const int closingAngleBracketPos = theType.lastIndexOf('>'); + if (closingAngleBracketPos > openAngleBracketPos) { + theType = theType.left(openAngleBracketPos) + + theType.mid(closingAngleBracketPos + 1); + } + } const int xrefCount = theType.count("&&"); const int refCount = theType.count('&') - 2 * xrefCount; const int ptrRefCount = theType.count('*') + refCount; diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index 927728d875..82e63d4983 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -1249,6 +1249,7 @@ void ClangdTestHighlighting::test_data() 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; + QTest::newRow("simple return") << 841 << 12 << 841 << 15 << QList<int>{C_LOCAL} << 0; } void ClangdTestHighlighting::test() diff --git a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp index 652d9540c8..7f8faa1edc 100644 --- a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp +++ b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp @@ -834,3 +834,9 @@ void assignmentTest() { struct S {} s; s = {}; } + +using FooPtrVector = std::vector<Foo *>; +FooPtrVector returnTest() { + FooPtrVector foo; + return foo; +} |