[SourceKit] Don't report DocInfo requests from other buffers

This commit is contained in:
Doug Gregor
2023-02-28 20:30:51 -08:00
parent 7a1c558899
commit 8f42a5d111

View File

@@ -770,6 +770,10 @@ public:
: SM(SM), BufferID(BufferID), References(References), Consumer(Consumer) {}
bool walkToNodePre(SyntaxNode Node) override {
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(Node.Range.getStart()))
return false;
unsigned Offset = SM.getLocOffsetInBuffer(Node.Range.getStart(), BufferID);
unsigned Length = Node.Range.getByteLength();
@@ -830,6 +834,11 @@ public:
auto passAnnotation = [&](UIdent Kind, SourceLoc Loc, Identifier Name) {
if (Loc.isInvalid())
return;
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(Loc))
return;
unsigned Offset = SM.getLocOffsetInBuffer(Loc, BufferID);
unsigned Length = Name.empty() ? 1 : Name.getLength();
reportRefsUntil(Offset);
@@ -922,6 +931,10 @@ static void addParameters(ArrayRef<Identifier> &ArgNames,
if (TypeRange.isInvalid())
continue;
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(TypeRange.Start))
continue;
unsigned StartOffs = SM.getLocOffsetInBuffer(TypeRange.Start, BufferID);
unsigned EndOffs =
SM.getLocOffsetInBuffer(Lexer::getLocForEndOfToken(SM, TypeRange.End),
@@ -984,6 +997,10 @@ public:
if (!isa<AbstractFunctionDecl>(D) && !isa<SubscriptDecl>(D))
return Action::Continue();
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(D->getLoc()))
return Action::SkipChildren();
unsigned Offset = SM.getLocOffsetInBuffer(D->getLoc(), BufferID);
auto Found = FuncEnts.end();
if (FuncEnts.front()->LocOffset == Offset) {
@@ -1137,6 +1154,11 @@ public:
return true;
if (isLocal(D))
return true;
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(D->getSourceRange().Start))
return false;
TextRange TR = getTextRange(D->getSourceRange());
unsigned LocOffset = getOffset(Range.getStart());
EntitiesStack.emplace_back(D, TypeOrExtensionDecl(), nullptr, TR, LocOffset,
@@ -1162,6 +1184,10 @@ public:
ReferenceMetaData Data) override {
if (Data.isImplicit || !Range.isValid())
return true;
// Ignore things that don't come from this buffer.
if (!SM.getRangeForBuffer(BufferID).contains(Range.getStart()))
return false;
unsigned StartOffset = getOffset(Range.getStart());
References.emplace_back(D, StartOffset, Range.getByteLength(), Ty);
return true;