@@ -770,6 +770,10 @@ class DocSyntaxWalker : public SyntaxModelWalker {
770770 : SM(SM), BufferID(BufferID), References(References), Consumer(Consumer) {}
771771
772772 bool walkToNodePre (SyntaxNode Node) override {
773+ // Ignore things that don't come from this buffer.
774+ if (!SM.getRangeForBuffer (BufferID).contains (Node.Range .getStart ()))
775+ return false ;
776+
773777 unsigned Offset = SM.getLocOffsetInBuffer (Node.Range .getStart (), BufferID);
774778 unsigned Length = Node.Range .getByteLength ();
775779
@@ -830,6 +834,11 @@ class DocSyntaxWalker : public SyntaxModelWalker {
830834 auto passAnnotation = [&](UIdent Kind, SourceLoc Loc, Identifier Name) {
831835 if (Loc.isInvalid ())
832836 return ;
837+
838+ // Ignore things that don't come from this buffer.
839+ if (!SM.getRangeForBuffer (BufferID).contains (Loc))
840+ return ;
841+
833842 unsigned Offset = SM.getLocOffsetInBuffer (Loc, BufferID);
834843 unsigned Length = Name.empty () ? 1 : Name.getLength ();
835844 reportRefsUntil (Offset);
@@ -922,6 +931,10 @@ static void addParameters(ArrayRef<Identifier> &ArgNames,
922931 if (TypeRange.isInvalid ())
923932 continue ;
924933
934+ // Ignore things that don't come from this buffer.
935+ if (!SM.getRangeForBuffer (BufferID).contains (TypeRange.Start ))
936+ continue ;
937+
925938 unsigned StartOffs = SM.getLocOffsetInBuffer (TypeRange.Start , BufferID);
926939 unsigned EndOffs =
927940 SM.getLocOffsetInBuffer (Lexer::getLocForEndOfToken (SM, TypeRange.End ),
@@ -984,6 +997,10 @@ class FuncWalker : public ASTWalker {
984997 if (!isa<AbstractFunctionDecl>(D) && !isa<SubscriptDecl>(D))
985998 return Action::Continue ();
986999
1000+ // Ignore things that don't come from this buffer.
1001+ if (!SM.getRangeForBuffer (BufferID).contains (D->getLoc ()))
1002+ return Action::SkipChildren ();
1003+
9871004 unsigned Offset = SM.getLocOffsetInBuffer (D->getLoc (), BufferID);
9881005 auto Found = FuncEnts.end ();
9891006 if (FuncEnts.front ()->LocOffset == Offset) {
@@ -1137,6 +1154,11 @@ class SourceDocASTWalker : public SourceEntityWalker {
11371154 return true ;
11381155 if (isLocal (D))
11391156 return true ;
1157+
1158+ // Ignore things that don't come from this buffer.
1159+ if (!SM.getRangeForBuffer (BufferID).contains (D->getSourceRange ().Start ))
1160+ return false ;
1161+
11401162 TextRange TR = getTextRange (D->getSourceRange ());
11411163 unsigned LocOffset = getOffset (Range.getStart ());
11421164 EntitiesStack.emplace_back (D, TypeOrExtensionDecl (), nullptr , TR, LocOffset,
@@ -1162,6 +1184,10 @@ class SourceDocASTWalker : public SourceEntityWalker {
11621184 ReferenceMetaData Data) override {
11631185 if (Data.isImplicit || !Range.isValid ())
11641186 return true ;
1187+ // Ignore things that don't come from this buffer.
1188+ if (!SM.getRangeForBuffer (BufferID).contains (Range.getStart ()))
1189+ return false ;
1190+
11651191 unsigned StartOffset = getOffset (Range.getStart ());
11661192 References.emplace_back (D, StartOffset, Range.getByteLength (), Ty);
11671193 return true ;
0 commit comments