diff --git a/include/swift/Index/Index.h b/include/swift/Index/Index.h index bea22854fbfef..5202cdfe08693 100644 --- a/include/swift/Index/Index.h +++ b/include/swift/Index/Index.h @@ -25,6 +25,7 @@ namespace index { void indexDeclContext(DeclContext *DC, IndexDataConsumer &consumer); void indexSourceFile(SourceFile *SF, IndexDataConsumer &consumer); void indexModule(ModuleDecl *module, IndexDataConsumer &consumer); +bool printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS); } // end namespace index } // end namespace swift diff --git a/lib/Index/Index.cpp b/lib/Index/Index.cpp index 80113399acf5b..cd6dcfa051093 100644 --- a/lib/Index/Index.cpp +++ b/lib/Index/Index.cpp @@ -73,7 +73,7 @@ printArtificialName(const swift::AbstractStorageDecl *ASD, AccessorKind AK, llvm llvm_unreachable("Unhandled AccessorKind in switch."); } -static bool printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS) { +bool index::printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS) { if (!D->hasName() && !isa(D)) { auto *FD = dyn_cast(D); if (!FD) diff --git a/lib/Refactoring/LocalRename.cpp b/lib/Refactoring/LocalRename.cpp index ae0a572e19242..7b2d64e7ca0b4 100644 --- a/lib/Refactoring/LocalRename.cpp +++ b/lib/Refactoring/LocalRename.cpp @@ -194,21 +194,13 @@ swift::ide::getRenameInfo(ResolvedCursorInfoPtr cursorInfo) { } class RenameRangeCollector : public IndexDataConsumer { - StringRef usr; + const ValueDecl *declToRename; std::unique_ptr stringStorage; std::vector locations; public: - RenameRangeCollector(StringRef usr) - : usr(usr), stringStorage(new StringScratchSpace()) {} - - RenameRangeCollector(const ValueDecl *D) - : stringStorage(new StringScratchSpace()) { - SmallString<64> SS; - llvm::raw_svector_ostream OS(SS); - printValueDeclUSR(D, OS); - usr = stringStorage->copyString(SS.str()); - } + RenameRangeCollector(const ValueDecl *declToRename) + : declToRename(declToRename), stringStorage(new StringScratchSpace()) {} RenameRangeCollector(RenameRangeCollector &&collector) = default; @@ -228,7 +220,7 @@ class RenameRangeCollector : public IndexDataConsumer { bool finishDependency(bool isClangModule) override { return true; } Action startSourceEntity(const IndexSymbol &symbol) override { - if (symbol.USR != usr) { + if (symbol.decl != declToRename) { return IndexDataConsumer::Continue; } auto loc = indexSymbolToRenameLoc(symbol); diff --git a/test/SourceKit/RelatedIdents/two_invalid_decls_with_same_base_name.swift b/test/SourceKit/RelatedIdents/two_invalid_decls_with_same_base_name.swift new file mode 100644 index 0000000000000..50d1de2499df4 --- /dev/null +++ b/test/SourceKit/RelatedIdents/two_invalid_decls_with_same_base_name.swift @@ -0,0 +1,6 @@ +struct Foo { + func bar(body: Invalid) {} + +// RUN: %sourcekitd-test -req=related-idents -pos=%(line + 1):8 %s -- %s + func bar(ignoreCase: Bool, body: Invalid) {} +}