ClangCodeModel: Fix template highlighting bug

We need to take into account that the ">>" in constructs such as
std::vector<std::pair<int, int>> is only one token on the clang side.

Change-Id: I90f002ca56f236032f6d39c338593a2ff7590061
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-04-15 13:54:02 +02:00
parent 8e8236e9e0
commit c80c724b52
8 changed files with 30 additions and 7 deletions

View File

@@ -115,6 +115,7 @@ bool ignore(ClangBackEnd::HighlightingType type)
case HighlightingType::TemplateTemplateParameter:
case HighlightingType::AngleBracketOpen:
case HighlightingType::AngleBracketClose:
case HighlightingType::DoubleAngleBracketClose:
case HighlightingType::TernaryIf:
case HighlightingType::TernaryElse:
return true;
@@ -149,6 +150,8 @@ TextEditor::HighlightingResult toHighlightingResult(
result.kind = CppTools::SemanticHighlighter::AngleBracketOpen;
else if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::AngleBracketClose))
result.kind = CppTools::SemanticHighlighter::AngleBracketClose;
else if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::DoubleAngleBracketClose))
result.kind = CppTools::SemanticHighlighter::DoubleAngleBracketClose;
else if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::TernaryIf))
result.kind = CppTools::SemanticHighlighter::TernaryIf;
else if (tokenInfo.types.mixinHighlightingTypes.contains(HighlightingType::TernaryElse))

View File

@@ -178,6 +178,7 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
for (int i = from; i < to; ++i) {
const HighlightingResult &result = m_watcher->future().resultAt(i);
if (result.kind != AngleBracketOpen && result.kind != AngleBracketClose
&& result.kind != DoubleAngleBracketClose
&& result.kind != TernaryIf && result.kind != TernaryElse) {
const QTextBlock block =
m_baseTextDocument->document()->findBlockByNumber(result.line - 1);
@@ -193,14 +194,18 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
parentheses.second = getClearedParentheses(parentheses.first);
}
Parenthesis paren;
if (result.kind == AngleBracketOpen)
if (result.kind == AngleBracketOpen) {
paren = {Parenthesis::Opened, '<', result.column - 1};
else if (result.kind == AngleBracketClose)
} else if (result.kind == AngleBracketClose) {
paren = {Parenthesis::Closed, '>', result.column - 1};
else if (result.kind == TernaryIf)
} else if (result.kind == DoubleAngleBracketClose) {
parentheses.second.append({Parenthesis::Closed, '>', result.column - 1});
paren = {Parenthesis::Closed, '>', result.column};
} else if (result.kind == TernaryIf) {
paren = {Parenthesis::Opened, '?', result.column - 1};
else if (result.kind == TernaryElse)
} else if (result.kind == TernaryElse) {
paren = {Parenthesis::Closed, ':', result.column - 1};
}
QTC_ASSERT(paren.pos != -1, continue);
paren.source = parenSource();
parentheses.second << paren;

View File

@@ -61,6 +61,7 @@ public:
VirtualFunctionDeclarationUse,
AngleBracketOpen,
AngleBracketClose,
DoubleAngleBracketClose,
TernaryIf,
TernaryElse,
};