[IDE] Update CursorInfo and FindRelatedIdents to treat property wrapper backing properties as the underlying property

This is the final piece to get rename and findRelatedIdents to include all foo
and $foo occurrences, for example, in the set of occurrences to be renamed or
shown, regardless of whether they were initiated on a foo or $foo.

Resolves rdar://problem/51695783.
This commit is contained in:
Nathan Hawes
2019-06-21 20:02:08 -07:00
parent d389652998
commit 91e2e35a77
5 changed files with 85 additions and 9 deletions

View File

@@ -1884,8 +1884,11 @@ private:
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
if (Cancelled)
return false;
if (auto *V = dyn_cast<VarDecl>(D))
D = V->getCanonicalVarDecl();
if (auto *V = dyn_cast<VarDecl>(D)) {
// Handle references to the implicitly generated vars in case statements
// matching multiple patterns
D = V->getCanonicalVarDecl();
}
if (D == Dcl)
return passId(Range);
return true;
@@ -1896,10 +1899,19 @@ private:
if (Cancelled)
return false;
if (auto *V = dyn_cast<VarDecl>(D))
if (auto *V = dyn_cast<VarDecl>(D)) {
D = V->getCanonicalVarDecl();
else if (CtorTyRef)
// If we have a backing property of a property wrapper, use the wrapped
// property instead (i.e. if this is $foo, pretend it's foo).
if (auto *Wrapped = V->getOriginalWrappedProperty()) {
assert(Range.getByteLength() > 1 && Range.str().front() == '$');
D = Wrapped;
Range = CharSourceRange(Range.getStart().getAdvancedLoc(1), Range.getByteLength() - 1);
}
} else if (CtorTyRef) {
D = CtorTyRef;
}
if (D == Dcl)
return passId(Range);