@@ -770,6 +770,10 @@ class DocSyntaxWalker : public SyntaxModelWalker {
770
770
: SM(SM), BufferID(BufferID), References(References), Consumer(Consumer) {}
771
771
772
772
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
+
773
777
unsigned Offset = SM.getLocOffsetInBuffer (Node.Range .getStart (), BufferID);
774
778
unsigned Length = Node.Range .getByteLength ();
775
779
@@ -830,6 +834,11 @@ class DocSyntaxWalker : public SyntaxModelWalker {
830
834
auto passAnnotation = [&](UIdent Kind, SourceLoc Loc, Identifier Name) {
831
835
if (Loc.isInvalid ())
832
836
return ;
837
+
838
+ // Ignore things that don't come from this buffer.
839
+ if (!SM.getRangeForBuffer (BufferID).contains (Loc))
840
+ return ;
841
+
833
842
unsigned Offset = SM.getLocOffsetInBuffer (Loc, BufferID);
834
843
unsigned Length = Name.empty () ? 1 : Name.getLength ();
835
844
reportRefsUntil (Offset);
@@ -922,6 +931,10 @@ static void addParameters(ArrayRef<Identifier> &ArgNames,
922
931
if (TypeRange.isInvalid ())
923
932
continue ;
924
933
934
+ // Ignore things that don't come from this buffer.
935
+ if (!SM.getRangeForBuffer (BufferID).contains (TypeRange.Start ))
936
+ continue ;
937
+
925
938
unsigned StartOffs = SM.getLocOffsetInBuffer (TypeRange.Start , BufferID);
926
939
unsigned EndOffs =
927
940
SM.getLocOffsetInBuffer (Lexer::getLocForEndOfToken (SM, TypeRange.End ),
@@ -984,6 +997,10 @@ class FuncWalker : public ASTWalker {
984
997
if (!isa<AbstractFunctionDecl>(D) && !isa<SubscriptDecl>(D))
985
998
return Action::Continue ();
986
999
1000
+ // Ignore things that don't come from this buffer.
1001
+ if (!SM.getRangeForBuffer (BufferID).contains (D->getLoc ()))
1002
+ return Action::SkipChildren ();
1003
+
987
1004
unsigned Offset = SM.getLocOffsetInBuffer (D->getLoc (), BufferID);
988
1005
auto Found = FuncEnts.end ();
989
1006
if (FuncEnts.front ()->LocOffset == Offset) {
@@ -1137,6 +1154,11 @@ class SourceDocASTWalker : public SourceEntityWalker {
1137
1154
return true ;
1138
1155
if (isLocal (D))
1139
1156
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
+
1140
1162
TextRange TR = getTextRange (D->getSourceRange ());
1141
1163
unsigned LocOffset = getOffset (Range.getStart ());
1142
1164
EntitiesStack.emplace_back (D, TypeOrExtensionDecl (), nullptr , TR, LocOffset,
@@ -1162,6 +1184,10 @@ class SourceDocASTWalker : public SourceEntityWalker {
1162
1184
ReferenceMetaData Data) override {
1163
1185
if (Data.isImplicit || !Range.isValid ())
1164
1186
return true ;
1187
+ // Ignore things that don't come from this buffer.
1188
+ if (!SM.getRangeForBuffer (BufferID).contains (Range.getStart ()))
1189
+ return false ;
1190
+
1165
1191
unsigned StartOffset = getOffset (Range.getStart ());
1166
1192
References.emplace_back (D, StartOffset, Range.getByteLength (), Ty);
1167
1193
return true ;
0 commit comments