forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user