diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-11-01 14:44:32 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-11-08 13:55:15 +0000 |
commit | 35e57ca748398edf569d357a7ca192ecc5fd8d5e (patch) | |
tree | 58269e9da4bb8d503493a86a0bc337ebe47a2329 | |
parent | f16589f96991d3801d2ec0a0068b5b231e1570fe (diff) |
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>
-rw-r--r-- | src/plugins/clangcodemodel/clangdclient.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 17fe277507..09f9cedd19 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -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); |