[SourceKit] Always check buffer in SemanticAnnotator

Make sure we don't ever try to record semantic tokens for a different
buffer. This works around an ASTWalker issue where it will walk macro
expanded bodies even in non-macro-expansion mode.

rdar://165420658
This commit is contained in:
Hamish Knight
2025-12-10 14:58:44 +00:00
parent cac74c361e
commit 7c11824db9
2 changed files with 44 additions and 5 deletions

View File

@@ -1027,12 +1027,11 @@ public:
if (!Range.isValid())
return;
// If we are walking into macro expansions, make sure we only report ranges
// from the requested buffer, not any buffers of child macro expansions.
if (IsWalkingMacroExpansionBuffer &&
SM.findBufferContainingLoc(Range.getStart()) != BufferID) {
// Make sure we only report from the requested buffer, not any buffers of
// child macro expansions.
if (SM.findBufferContainingLoc(Range.getStart()) != BufferID)
return;
}
unsigned ByteOffset = SM.getLocOffsetInBuffer(Range.getStart(), BufferID);
unsigned Length = Range.getByteLength();
auto Kind = ContextFreeCodeCompletionResult::getCodeCompletionDeclKind(D);