[SourceKit] In related identes, report underlying var of shorthand if let binding

This commit is contained in:
Alex Hoppen
2022-05-05 14:24:28 +02:00
parent 64e27a270e
commit d0d3d42967
2 changed files with 70 additions and 0 deletions

View File

@@ -2234,6 +2234,41 @@ private:
return true;
}
bool walkToStmtPre(Stmt *S) override {
if (Cancelled)
return false;
if (auto CondStmt = dyn_cast<LabeledConditionalStmt>(S)) {
for (const StmtConditionElement &Cond : CondStmt->getCond()) {
if (Cond.getKind() != StmtConditionElement::CK_PatternBinding) {
continue;
}
auto Init = dyn_cast<DeclRefExpr>(Cond.getInitializer());
if (!Init) {
continue;
}
auto ReferencedVar = dyn_cast_or_null<VarDecl>(Init->getDecl());
if (!ReferencedVar) {
continue;
}
Cond.getPattern()->forEachVariable([&](VarDecl *DeclaredVar) {
if (DeclaredVar->getLoc() != Init->getLoc()) {
return;
}
assert(DeclaredVar->getName() == ReferencedVar->getName());
if (DeclaredVar == Dcl) {
RelatedDecls.push_back(ReferencedVar);
}
if (ReferencedVar == Dcl) {
RelatedDecls.push_back(DeclaredVar);
}
});
}
}
return true;
}
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
if (Cancelled)
return false;