diff --git a/src/libs/clangsupport/clangsupport_global.h b/src/libs/clangsupport/clangsupport_global.h index 7b63feb381a..7cc160b932d 100644 --- a/src/libs/clangsupport/clangsupport_global.h +++ b/src/libs/clangsupport/clangsupport_global.h @@ -107,7 +107,9 @@ enum class HighlightingType : quint8 ObjectiveCProperty, ObjectiveCMethod, TemplateTypeParameter, - TemplateTemplateParameter + TemplateTemplateParameter, + AngleBracketOpen, + AngleBracketClose, }; enum class StorageClass : quint8 diff --git a/src/plugins/clangcodemodel/clanghighlightingresultreporter.cpp b/src/plugins/clangcodemodel/clanghighlightingresultreporter.cpp index 7f1e6dc1816..1d96fc7b2d7 100644 --- a/src/plugins/clangcodemodel/clanghighlightingresultreporter.cpp +++ b/src/plugins/clangcodemodel/clanghighlightingresultreporter.cpp @@ -112,6 +112,8 @@ bool ignore(ClangBackEnd::HighlightingType type) case HighlightingType::ObjectiveCMethod: case HighlightingType::TemplateTypeParameter: case HighlightingType::TemplateTemplateParameter: + case HighlightingType::AngleBracketOpen: + case HighlightingType::AngleBracketClose: return true; } @@ -136,9 +138,15 @@ TextEditor::TextStyles toTextStyles(ClangBackEnd::HighlightingTypes types) TextEditor::HighlightingResult toHighlightingResult( const ClangBackEnd::TokenInfoContainer &tokenInfo) { + using ClangBackEnd::HighlightingType; const auto textStyles = toTextStyles(tokenInfo.types); - - return {tokenInfo.line, tokenInfo.column, tokenInfo.length, textStyles}; + TextEditor::HighlightingResult result(tokenInfo.line, tokenInfo.column, tokenInfo.length, + textStyles); + if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::AngleBracketOpen)) + result.kind = 1; + else if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::AngleBracketClose)) + result.kind = 2; + return result; } } // anonymous diff --git a/src/plugins/cpptools/semantichighlighter.cpp b/src/plugins/cpptools/semantichighlighter.cpp index a0c21c3b97e..431bf1849cc 100644 --- a/src/plugins/cpptools/semantichighlighter.cpp +++ b/src/plugins/cpptools/semantichighlighter.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -159,6 +160,28 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to) QTC_ASSERT(highlighter, return); incrementalApplyExtraAdditionalFormats(highlighter, m_watcher->future(), from, to, m_formatMap, &splitRawStringLiteral); + + // Add information about angle brackets, so they can be highlighted/animated. + QPair parentheses; + for (int i = from; i < to; ++i) { + const HighlightingResult &result = m_watcher->future().resultAt(i); + if (result.kind == 0) + continue; + if (parentheses.first.isValid() && result.line - 1 > parentheses.first.blockNumber()) { + TextDocumentLayout::setParentheses(parentheses.first, parentheses.second); + parentheses = {}; + } + if (!parentheses.first.isValid()) { + parentheses.first = m_baseTextDocument->document()->findBlockByNumber(result.line - 1); + parentheses.second = TextDocumentLayout::parentheses(parentheses.first); + } + if (result.kind == 1) + parentheses.second << Parenthesis(Parenthesis::Opened, '<', result.column - 1); + else + parentheses.second << Parenthesis(Parenthesis::Closed, '>', result.column - 1); + } + if (parentheses.first.isValid()) + TextDocumentLayout::setParentheses(parentheses.first, parentheses.second); } void SemanticHighlighter::onHighlighterFinished() diff --git a/src/tools/clangbackend/source/tokeninfo.cpp b/src/tools/clangbackend/source/tokeninfo.cpp index ed2fd0bf41c..7eb09a04bc2 100644 --- a/src/tools/clangbackend/source/tokeninfo.cpp +++ b/src/tools/clangbackend/source/tokeninfo.cpp @@ -591,6 +591,14 @@ void TokenInfo::punctuationOrOperatorKind() break; } + if (m_types.mixinHighlightingTypes.empty() && kind != CXCursor_InclusionDirective) { + const ClangString spelling = m_token->spelling(); + if (spelling == "<") + m_types.mixinHighlightingTypes.push_back(HighlightingType::AngleBracketOpen); + else if (spelling == ">") + m_types.mixinHighlightingTypes.push_back(HighlightingType::AngleBracketClose); + } + if (isOutputArgument()) m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument); } diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp index 9d9251483ad..14008331e2f 100644 --- a/tests/unit/unittest/tokenprocessor-test.cpp +++ b/tests/unit/unittest/tokenprocessor-test.cpp @@ -870,16 +870,18 @@ TEST_F(TokenProcessor, LessThanOperator) TEST_F(TokenProcessor, LessThanPunctuation) { - const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19)); + const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 10)); - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Punctuation)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Punctuation, + HighlightingType::AngleBracketOpen)); } TEST_F(TokenProcessor, GreaterThanPunctuation) { const auto infos = translationUnit.tokenInfosInRange(sourceRange(247, 19)); - ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::Punctuation)); + ASSERT_THAT(infos[4], HasTwoTypes(HighlightingType::Punctuation, + HighlightingType::AngleBracketClose)); } TEST_F(TokenProcessor, Comment) @@ -1139,7 +1141,8 @@ TEST_F(TokenProcessor, StaticCastPunctation) { const auto infos = translationUnit.tokenInfosInRange(sourceRange(328, 64)); - ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Punctuation)); + ASSERT_THAT(infos[1], HasTwoTypes(HighlightingType::Punctuation, + HighlightingType::AngleBracketOpen)); ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Punctuation)); ASSERT_THAT(infos[5], HasOnlyType(HighlightingType::Punctuation)); }