@@ -193,7 +193,7 @@ class RenameRangeCollector : public IndexDataConsumer {
193
193
194
194
// / Take the resuls from the collector.
195
195
// / This invalidates the collector and must only be called once.
196
- RenameLocs takeResults () {
196
+ RenameLocs takeResults () && {
197
197
return RenameLocs (locations, std::move (stringStorage));
198
198
}
199
199
@@ -278,7 +278,7 @@ RenameRangeCollector::indexSymbolToRenameLoc(const index::IndexSymbol &symbol) {
278
278
// /
279
279
// / This \c DeclContext contains all possible references to \c VD within the
280
280
// / file.
281
- DeclContext *getRenameScope (ValueDecl *VD) {
281
+ DeclContext *getRenameScope (const ValueDecl *VD) {
282
282
auto *Scope = VD->getDeclContext ();
283
283
// There may be sibling decls that the renamed symbol is visible from.
284
284
switch (Scope->getContextKind ()) {
@@ -303,15 +303,15 @@ DeclContext *getRenameScope(ValueDecl *VD) {
303
303
return Scope;
304
304
}
305
305
306
- // / Get the `RenameInfo` at `startLoc` and validate that we can perform local
306
+ // / Get the declaration at `startLoc` and validate that we can perform local
307
307
// / rename on it (e.g. checking that the original definition isn't a system
308
308
// / symbol).
309
309
// /
310
- // / If the validation succeeds, return the `RenameInfo `, otherwise add an error
311
- // / to `diags` and return `None `.
312
- static llvm::Optional<RenameInfo>
313
- getRenameInfoForLocalRename (SourceFile *sourceFile, SourceLoc startLoc,
314
- DiagnosticEngine &diags) {
310
+ // / If the validation succeeds, return the `ValueDecl `, otherwise add an error
311
+ // / to `diags` and return `nullptr `.
312
+ static ValueDecl * getDeclForLocalRename (SourceFile *sourceFile,
313
+ SourceLoc startLoc,
314
+ DiagnosticEngine &diags) {
315
315
auto cursorInfo = evaluateOrDefault (
316
316
sourceFile->getASTContext ().evaluator ,
317
317
CursorInfoRequest{CursorInfoOwner (sourceFile, startLoc)},
@@ -320,55 +320,56 @@ getRenameInfoForLocalRename(SourceFile *sourceFile, SourceLoc startLoc,
320
320
llvm::Optional<RenameInfo> info = getRenameInfo (cursorInfo);
321
321
if (!info) {
322
322
diags.diagnose (startLoc, diag::unresolved_location);
323
- return llvm::None ;
323
+ return nullptr ;
324
324
}
325
325
326
326
switch (info->Availability .AvailableKind ) {
327
327
case RefactorAvailableKind::Available:
328
328
break ;
329
329
case RefactorAvailableKind::Unavailable_system_symbol:
330
330
diags.diagnose (startLoc, diag::decl_is_system_symbol, info->VD ->getName ());
331
- return llvm::None ;
331
+ return nullptr ;
332
332
case RefactorAvailableKind::Unavailable_has_no_location:
333
333
diags.diagnose (startLoc, diag::value_decl_no_loc, info->VD ->getName ());
334
- return llvm::None ;
334
+ return nullptr ;
335
335
case RefactorAvailableKind::Unavailable_has_no_name:
336
336
diags.diagnose (startLoc, diag::decl_has_no_name);
337
- return llvm::None ;
337
+ return nullptr ;
338
338
case RefactorAvailableKind::Unavailable_has_no_accessibility:
339
339
diags.diagnose (startLoc, diag::decl_no_accessibility);
340
- return llvm::None ;
340
+ return nullptr ;
341
341
case RefactorAvailableKind::Unavailable_decl_from_clang:
342
342
diags.diagnose (startLoc, diag::decl_from_clang);
343
- return llvm::None ;
343
+ return nullptr ;
344
344
case RefactorAvailableKind::Unavailable_decl_in_macro:
345
345
diags.diagnose (startLoc, diag::decl_in_macro);
346
- return llvm::None ;
346
+ return nullptr ;
347
347
}
348
348
349
- return info;
349
+ return info-> VD ;
350
350
}
351
351
352
- RenameLocs swift::ide::localRenameLocs (SourceFile *SF, RenameInfo renameInfo) {
352
+ RenameLocs swift::ide::localRenameLocs (SourceFile *SF,
353
+ const ValueDecl *valueDecl) {
353
354
DeclContext *RenameScope = SF;
354
- if (! RenameScope) {
355
+ if (RenameScope) {
355
356
// If the value is declared in a DeclContext that's a child of the file in
356
357
// which we are performing the rename, we can limit our analysis to this
357
358
// decl context.
358
359
//
359
360
// Cases where the rename scope is not a child of the source file include
360
361
// if we are getting related identifiers of a type A that is defined in
361
362
// another file. In this case, we need to analyze the entire file.
362
- auto DeclarationScope = getRenameScope (renameInfo. VD );
363
+ auto DeclarationScope = getRenameScope (valueDecl );
363
364
if (DeclarationScope->isChildContextOf (SF)) {
364
365
RenameScope = DeclarationScope;
365
366
}
366
367
}
367
368
368
- RenameRangeCollector rangeCollector (renameInfo. VD );
369
+ RenameRangeCollector rangeCollector (valueDecl );
369
370
indexDeclContext (RenameScope, rangeCollector);
370
371
371
- return rangeCollector.takeResults ();
372
+ return std::move ( rangeCollector) .takeResults ();
372
373
}
373
374
374
375
CancellableResult<std::vector<SyntacticRenameRangeDetails>>
@@ -385,13 +386,12 @@ swift::ide::findLocalRenameRanges(SourceFile *SF, RangeConfig Range) {
385
386
Diags.addConsumer (DiagConsumer);
386
387
387
388
auto StartLoc = Lexer::getLocForStartOfToken (SM, Range.getStart (SM));
388
- llvm::Optional<RenameInfo> info =
389
- getRenameInfoForLocalRename (SF, StartLoc, Diags);
390
- if (!info || DiagConsumer.didErrorOccur ()) {
389
+ ValueDecl *declToRename = getDeclForLocalRename (SF, StartLoc, Diags);
390
+ if (!declToRename || DiagConsumer.didErrorOccur ()) {
391
391
return ResultType::failure (ErrBuffer);
392
392
}
393
393
394
- RenameLocs RenameRanges = localRenameLocs (SF, *info );
394
+ RenameLocs RenameRanges = localRenameLocs (SF, declToRename );
395
395
396
396
return findSyntacticRenameRanges (SF, RenameRanges.getLocations (),
397
397
/* NewName=*/ StringRef ());
0 commit comments