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>
This commit is contained in:
Christian Kandeler
2022-04-14 16:56:06 +02:00
parent 411b82347a
commit 0cb569a39b

View File

@@ -2586,6 +2586,7 @@ private:
const AstNode &m_ast; const AstNode &m_ast;
const QTextDocument * const m_doc; const QTextDocument * const m_doc;
const QString &m_docContent; 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, // 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()) if (m_future.isCanceled())
return; 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::Ours:
case AstNode::FileStatus::Unknown: case AstNode::FileStatus::Unknown:
collectFromNode(node); collectFromNode(node);
@@ -3976,6 +3983,7 @@ void ExtraHighlightingResultsCollector::visitNode(const AstNode &node)
break; break;
} }
} }
m_currentFileStatus = prevFileStatus;
} }
bool ClangdClient::FollowSymbolData::defLinkIsAmbiguous() const bool ClangdClient::FollowSymbolData::defLinkIsAmbiguous() const