[RangeInfo] When reporting referenced decls in a given range, exclude those whose decl context is out of the current file.

This commit is contained in:
Xi Ge
2016-12-19 16:01:40 -08:00
parent eb80cdd8ce
commit 87a4b8a07e
2 changed files with 32 additions and 10 deletions

View File

@@ -349,16 +349,21 @@ public:
}
void analyze(ASTNode Node) {
Decl *D = Node.is<Decl*>() ? Node.get<Decl*>() : nullptr;
// Collect declared decls in the range.
if (Node.is<Decl*>()) {
if (auto *VD = dyn_cast<ValueDecl>(Node.get<Decl*>())) {
if (auto *VD = dyn_cast_or_null<ValueDecl>(D)) {
if (isContainedInSelection(CharSourceRange(SM, VD->getStartLoc(),
VD->getEndLoc())))
pushBackDeclUniquely(DeclaredDecls, VD);
}
}
auto &DCInfo = getCurrentDC();
switch (getRangeMatchKind(Node.getSourceRange())) {
case RangeMatchKind::NoneMatch:
// PatternBindingDecl is not visited; we need to explicitly analyze here.
if (auto *VA = dyn_cast_or_null<VarDecl>(D))
analyze(VA->getParentPatternBinding());
return;
case RangeMatchKind::RangeMatch:
Result = getSingleNodeKind(Node);
@@ -398,6 +403,11 @@ public:
void analyzeDeclRef(ValueDecl *VD, CharSourceRange Range) {
if (!isContainedInSelection(Range))
return;
// If the VD is declared outside of current file, exclude such decl.
if (VD->getDeclContext()->getParentSourceFile() != &File)
return;
// Collect referenced decls in the range.
pushBackDeclUniquely(ReferencedDecls, VD);
}