mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Change RenameRangeCollector::startSourceEntity to use early returns
This commit is contained in:
@@ -53,7 +53,7 @@ struct RenameLoc {
|
||||
/// The column at which the base name (excluding trivia) starts (1-based).
|
||||
unsigned Column;
|
||||
|
||||
/// /// The offset at which the related name starts.
|
||||
/// The offset at which the related name starts.
|
||||
unsigned Offset;
|
||||
|
||||
/// The length of the base name in the related identifier. For functions,
|
||||
|
||||
@@ -207,21 +207,25 @@ private:
|
||||
bool finishDependency(bool isClangModule) override { return true; }
|
||||
|
||||
Action startSourceEntity(const IndexSymbol &symbol) override {
|
||||
if (symbol.USR == usr) {
|
||||
if (auto loc = indexSymbolToRenameLoc(symbol)) {
|
||||
// Inside capture lists like `{ [test] in }`, 'test' refers to both the
|
||||
// newly declared, captured variable and the referenced variable it is
|
||||
// initialized from. Make sure to only rename it once.
|
||||
auto existingLoc = llvm::find_if(locations, [&](RenameLoc searchLoc) {
|
||||
return searchLoc.Line == loc->Line && searchLoc.Column == loc->Column;
|
||||
});
|
||||
if (existingLoc == locations.end()) {
|
||||
locations.push_back(std::move(*loc));
|
||||
} else {
|
||||
assert(existingLoc->OldName == loc->OldName &&
|
||||
"Asked to do a different rename for the same location?");
|
||||
}
|
||||
}
|
||||
if (symbol.USR != usr) {
|
||||
return IndexDataConsumer::Continue;
|
||||
}
|
||||
auto loc = indexSymbolToRenameLoc(symbol);
|
||||
if (!loc) {
|
||||
return IndexDataConsumer::Continue;
|
||||
}
|
||||
|
||||
// Inside capture lists like `{ [test] in }`, 'test' refers to both the
|
||||
// newly declared, captured variable and the referenced variable it is
|
||||
// initialized from. Make sure to only rename it once.
|
||||
auto existingLoc = llvm::find_if(locations, [&](RenameLoc searchLoc) {
|
||||
return searchLoc.Line == loc->Line && searchLoc.Column == loc->Column;
|
||||
});
|
||||
if (existingLoc == locations.end()) {
|
||||
locations.push_back(std::move(*loc));
|
||||
} else {
|
||||
assert(existingLoc->OldName == loc->OldName &&
|
||||
"Asked to do a different rename for the same location?");
|
||||
}
|
||||
return IndexDataConsumer::Continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user