[SourceKit] In related identifiers, directly construct an array of ranges instead of putting them in an array first

After implementing related identifiers in terms of rename, this step seems to no longer be necessary.
This commit is contained in:
Alex Hoppen
2023-09-15 13:08:02 -07:00
parent ada3076628
commit bc3c8fc47a

View File

@@ -2580,29 +2580,14 @@ void SwiftLangSupport::findRelatedIdentifiersInFile(
std::vector<ResolvedLoc> ResolvedLocs =
resolveRenameLocations(Locs.getLocations(), *SrcFile, Diags);
// Record ranges in a set first so we don't record some ranges twice.
// This could happen in capture lists where e.g. `[foo]` is both the
// reference of the captured variable and the declaration of the
// variable usable in the closure.
llvm::SmallDenseSet<std::pair<unsigned, unsigned>, 8> RangesSet;
for (auto ResolvedLoc : ResolvedLocs) {
if (ResolvedLoc.Range.isInvalid()) {
continue;
}
unsigned Offset = SrcMgr.getLocOffsetInBuffer(
ResolvedLoc.Range.getStart(), BufferID);
RangesSet.insert({Offset, ResolvedLoc.Range.getByteLength()});
Ranges.emplace_back(Offset, ResolvedLoc.Range.getByteLength());
}
// Sort ranges so we get deterministic output.
Ranges.insert(Ranges.end(), RangesSet.begin(), RangesSet.end());
llvm::sort(Ranges,
[](const std::pair<unsigned, unsigned> &LHS,
const std::pair<unsigned, unsigned> &RHS) -> bool {
if (LHS.first == RHS.first) {
return LHS.second < RHS.second;
} else {
return LHS.first < RHS.first;
}
});
};
Action();
RelatedIdentsInfo Info;