aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2022-04-14 16:56:06 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2022-04-19 14:04:35 +0000
commit0cb569a39bade3c9e4ddacb2bde32e616b10739e (patch)
tree3a522bd19c800b3432508a4a76fd842cda9fc1a8
parent411b82347a3e8188552f14f2516efa49e3cd642e (diff)
ClangCodeModel: Fix check for AST nodes from included files
If an AST node contains no file info, then we must use the one of the parent node, in order not to create highlighting results for tokens from other files. Fixes: QTCREATORBUG-27384 Change-Id: I7c6f0c06063df9ce76feef333907d9d4f07a38e5 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/plugins/clangcodemodel/clangdclient.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp
index f30c18aa7f..cc8e7c8dc0 100644
--- a/src/plugins/clangcodemodel/clangdclient.cpp
+++ b/src/plugins/clangcodemodel/clangdclient.cpp
@@ -2586,6 +2586,7 @@ private:
const AstNode &m_ast;
const QTextDocument * const m_doc;
const QString &m_docContent;
+ AstNode::FileStatus m_currentFileStatus = AstNode::FileStatus::Unknown;
};
// clangd reports also the #ifs, #elses and #endifs around the disabled code as disabled,
@@ -3961,7 +3962,13 @@ void ExtraHighlightingResultsCollector::visitNode(const AstNode &node)
{
if (m_future.isCanceled())
return;
- switch (node.fileStatus(m_filePath)) {
+ const AstNode::FileStatus prevFileStatus = m_currentFileStatus;
+ m_currentFileStatus = node.fileStatus(m_filePath);
+ if (m_currentFileStatus == AstNode::FileStatus::Unknown
+ && prevFileStatus != AstNode::FileStatus::Ours) {
+ m_currentFileStatus = prevFileStatus;
+ }
+ switch (m_currentFileStatus) {
case AstNode::FileStatus::Ours:
case AstNode::FileStatus::Unknown:
collectFromNode(node);
@@ -3976,6 +3983,7 @@ void ExtraHighlightingResultsCollector::visitNode(const AstNode &node)
break;
}
}
+ m_currentFileStatus = prevFileStatus;
}
bool ClangdClient::FollowSymbolData::defLinkIsAmbiguous() const