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:
Christian Kandeler
2020-10-15 12:06:14 +02:00
parent 8112a00432
commit d8c1e51bfe
5 changed files with 51 additions and 7 deletions

View File

@@ -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()