ClangCodeModel: Make sure not to overwrite macros with their expansion

... when highlighting with clangd.

Change-Id: I89ec8bf5a1ed4d43e0e9a398b26705df00ca9a46
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-11-01 14:44:32 +01:00
parent f16589f969
commit 35e57ca748

View File

@@ -3140,6 +3140,18 @@ void ExtraHighlightingResultsCollector::insertResult(const HighlightingResult &r
return;
const auto it = std::lower_bound(m_results.begin(), m_results.end(), result, lessThan);
if (it == m_results.end() || *it != result) {
// Prevent inserting expansions for function-like macros. For instance:
// #define TEST() "blubb"
// const char *s = TEST();
// The macro name is always shorter than the expansion and starts at the same
// location, so it should occur right before the insertion position.
if (it > m_results.begin() && (it - 1)->line == result.line
&& (it - 1)->column == result.column
&& (it - 1)->textStyles.mainStyle == C_PREPROCESSOR) {
return;
}
qCDebug(clangdLogHighlight) << "adding additional highlighting result"
<< result.line << result.column << result.length;
m_results.insert(it, result);