From b1e73ca45dd1dd9ce28227b8c986fdfcee892ee2 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 30 May 2022 15:35:13 +0200 Subject: [PATCH] ClangCodeModel: Try harder to catch bogus AST ranges String literals that are adjacent after preprocessing are reported as a single AST node, leading to potentially wrong highlighting. We can catch this condition at least for the case where there are semantic tokens in between the string components. Fixes: QTCREATORBUG-27601 Change-Id: If023d06db74bd6cfefa670649f0e733ceaaede2d Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- .../clangcodemodel/clangdsemantichighlighting.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp b/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp index e3c6f08bdb9..b37605af128 100644 --- a/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp +++ b/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp @@ -482,6 +482,15 @@ void ExtraHighlightingResultsCollector::insertResult(const HighlightingResult &r return; } + // Bogus ranges; e.g. QTCREATORBUG-27601 + if (it != m_results.end()) { + const int nextStartPos = Utils::Text::positionInText(m_doc, it->line, it->column); + const int resultEndPos = Utils::Text::positionInText(m_doc, result.line, result.column) + + result.length; + if (resultEndPos > nextStartPos) + return; + } + qCDebug(clangdLogHighlight) << "adding additional highlighting result" << result.line << result.column << result.length; m_results.insert(it, result);