[Index] Handle shorthand if let/closure captures in local rename

Update rename to pull the outermost-declaration so that references are correctly found.

Rather than keeping suppressed locations in the current parent, keep
them for the whole index. Local rename starts the lookup from the
innermost context it can, which could be a closure. In that case there
is no parent decl on the stack and thus no where to store the locations
to suppress. We could have a specific store for this case, but there
shouldn't be that many of these and they're relatively cheap to store
anyway.

Resolves rdar://104568539.
This commit is contained in:
Ben Barham
2023-01-23 12:28:24 -08:00
parent 1a597c5ab7
commit 4cc7167b60
7 changed files with 60 additions and 36 deletions

View File

@@ -1172,6 +1172,7 @@ static bool passCursorInfoForDecl(
});
return false;
}
if (MainInfo.VD != OrigInfo.VD && !OrigInfo.Unavailable) {
CursorSymbolInfo &CtorSymbol = Symbols.emplace_back();
if (auto Err =
@@ -1182,16 +1183,21 @@ static bool passCursorInfoForDecl(
Symbols.pop_back();
}
}
for (auto D : Info.getShorthandShadowedDecls()) {
CursorSymbolInfo &SymbolInfo = Symbols.emplace_back();
DeclInfo DInfo(D, Type(), /*IsRef=*/true, /*IsDynamic=*/false,
ArrayRef<NominalTypeDecl *>(), Invoc);
if (auto Err =
fillSymbolInfo(SymbolInfo, DInfo, Info.getLoc(), AddSymbolGraph,
Lang, Invoc, PreviousSnaps, Allocator)) {
// Ignore but make sure to remove the partially-filled symbol
llvm::handleAllErrors(std::move(Err), [](const llvm::StringError &E) {});
Symbols.pop_back();
// Add in shadowed declarations if on a decl. For references just go to the
// actual declaration.
if (!Info.isRef()) {
for (auto D : Info.getShorthandShadowedDecls()) {
CursorSymbolInfo &SymbolInfo = Symbols.emplace_back();
DeclInfo DInfo(D, Type(), /*IsRef=*/true, /*IsDynamic=*/false,
ArrayRef<NominalTypeDecl *>(), Invoc);
if (auto Err =
fillSymbolInfo(SymbolInfo, DInfo, Info.getLoc(), AddSymbolGraph,
Lang, Invoc, PreviousSnaps, Allocator)) {
// Ignore but make sure to remove the partially-filled symbol
llvm::handleAllErrors(std::move(Err), [](const llvm::StringError &E) {});
Symbols.pop_back();
}
}
}