16
16
#include " swift/AST/USRGeneration.h"
17
17
#include " swift/Basic/StringExtras.h"
18
18
#include " swift/Frontend/PrintingDiagnosticConsumer.h"
19
+ #include " swift/IDE/IDEBridging.h"
19
20
#include " swift/Index/Index.h"
20
21
21
22
using namespace swift ::refactoring;
@@ -44,6 +45,31 @@ struct RenameRefInfo {
44
45
bool IsArgLabel; // /< Whether Loc is on an arg label, rather than base name.
45
46
};
46
47
48
+ #if SWIFT_BUILD_SWIFT_SYNTAX
49
+ // / Returns `true` if the `RefInfo` points to a location that doesn't have any
50
+ // / arguments. For example, returns `true` for `Foo.init` but `false` for
51
+ // / `Foo.init()` or `Foo.init(a: 1)`.
52
+ static bool
53
+ isReferenceWithoutArguments (const llvm::Optional<RenameRefInfo> &refInfo) {
54
+ if (!refInfo) {
55
+ return false ;
56
+ }
57
+ if (refInfo->IsArgLabel ) {
58
+ return false ;
59
+ }
60
+ BridgedSourceLoc Loc (refInfo->Loc );
61
+ BridgedResolvedLocVector bridgedResolvedLocs =
62
+ swift_SwiftIDEUtilsBridging_runNameMatcher (
63
+ refInfo->SF ->getExportedSourceFile (), &Loc, 1 );
64
+ std::vector<ResolvedLoc> resolvedLocs = bridgedResolvedLocs.takeUnbridged ();
65
+ if (!resolvedLocs.empty ()) {
66
+ ResolvedLoc resolvedLoc = resolvedLocs.front ();
67
+ return resolvedLoc.labelRanges .empty ();
68
+ }
69
+ return false ;
70
+ }
71
+ #endif // SWIFT_BUILD_SWIFT_SYNTAX
72
+
47
73
static llvm::Optional<RefactorAvailabilityInfo>
48
74
renameAvailabilityInfo (const ValueDecl *VD,
49
75
llvm::Optional<RenameRefInfo> RefInfo) {
@@ -88,12 +114,11 @@ renameAvailabilityInfo(const ValueDecl *VD,
88
114
if (!CD->getParameters ()->size ())
89
115
return llvm::None;
90
116
91
- if (RefInfo && !RefInfo->IsArgLabel ) {
92
- NameMatcher Matcher (*(RefInfo->SF ));
93
- auto Resolved = Matcher.resolve ({RefInfo->Loc });
94
- if (Resolved.labelRanges .empty ())
95
- return llvm::None;
117
+ #if SWIFT_BUILD_SWIFT_SYNTAX
118
+ if (isReferenceWithoutArguments (RefInfo)) {
119
+ return llvm::None;
96
120
}
121
+ #endif
97
122
}
98
123
99
124
// Disallow renaming 'callAsFunction' method with no arguments.
@@ -104,12 +129,11 @@ renameAvailabilityInfo(const ValueDecl *VD,
104
129
if (!FD->getParameters ()->size ())
105
130
return llvm::None;
106
131
107
- if (RefInfo && !RefInfo->IsArgLabel ) {
108
- NameMatcher Matcher (*(RefInfo->SF ));
109
- auto Resolved = Matcher.resolve ({RefInfo->Loc });
110
- if (Resolved.labelRanges .empty ())
111
- return llvm::None;
132
+ #if SWIFT_BUILD_SWIFT_SYNTAX
133
+ if (isReferenceWithoutArguments (RefInfo)) {
134
+ return llvm::None;
112
135
}
136
+ #endif
113
137
}
114
138
}
115
139
}
0 commit comments