forked from qt-creator/qt-creator
ClangCodeModel: Support highlighting angle brackets
... in template declarations and instantiations. Fixes: QTCREATORBUG-16799 Change-Id: I82bc6411ca980ecbe2a6c70ae37580166a4b89e9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -107,7 +107,9 @@ enum class HighlightingType : quint8
|
||||
ObjectiveCProperty,
|
||||
ObjectiveCMethod,
|
||||
TemplateTypeParameter,
|
||||
TemplateTemplateParameter
|
||||
TemplateTemplateParameter,
|
||||
AngleBracketOpen,
|
||||
AngleBracketClose,
|
||||
};
|
||||
|
||||
enum class StorageClass : quint8
|
||||
|
@@ -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
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -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<QTextBlock, Parentheses> 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()
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user