Skip to content

Commit e26c76d

Browse files
committed
[SourceKit] Migrate getNotableRegions to new NameMatcher in swift-syntax
1 parent a5530ce commit e26c76d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/swift/AST/DiagnosticsRefactoring.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
ERROR(invalid_name, none, "'%0' is not a valid name", (StringRef))
2828

29+
ERROR(extract_function_not_supported_swiftsyntax_missing, none, "Extract Function is not supported because sourcekitd was built without swift-syntax", ())
30+
2931
ERROR(invalid_location, none, "given location is not valid", ())
3032

3133
ERROR(arity_mismatch, none, "the given new name '%0' does not match the arity of the old name '%1'", (StringRef, StringRef))

lib/Refactoring/ExtractFunction.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static SourceLoc getNewFuncInsertLoc(DeclContext *DC,
7777
return SourceLoc();
7878
}
7979

80+
#if SWIFT_BUILD_SWIFT_SYNTAX
8081
static std::vector<NoteRegion>
8182
getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name) {
8283
auto InputBuffer =
@@ -99,8 +100,7 @@ getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name) {
99100
SourceLoc NameLoc = SM.getLocForOffset(BufferId, NameOffset);
100101
auto LineAndCol = SM.getLineAndColumnInBuffer(NameLoc);
101102

102-
NameMatcher Matcher(*Instance->getPrimarySourceFile());
103-
auto Resolved = Matcher.resolve(llvm::makeArrayRef(NameLoc), llvm::None);
103+
auto Resolved = runNameMatcher(*Instance->getPrimarySourceFile(), NameLoc);
104104
assert(!Resolved.empty() && "Failed to resolve generated func name loc");
105105

106106
RenameLoc RenameConfig = {LineAndCol.first, LineAndCol.second,
@@ -122,6 +122,7 @@ getNotableRegions(StringRef SourceText, unsigned NameOffset, StringRef Name) {
122122

123123
return NoteRegions;
124124
}
125+
#endif // SWIFT_BUILD_SWIFT_SYNTAX
125126

126127
bool RefactoringActionExtractFunction::isApplicable(
127128
const ResolvedRangeInfo &Info, DiagnosticEngine &Diag) {
@@ -142,6 +143,11 @@ bool RefactoringActionExtractFunction::isApplicable(
142143
}
143144

144145
bool RefactoringActionExtractFunction::performChange() {
146+
#if !SWIFT_BUILD_SWIFT_SYNTAX
147+
DiagEngine.diagnose(SourceLoc(),
148+
diag::extract_function_not_supported_swiftsyntax_missing);
149+
return true;
150+
#else
145151
// Check if the new name is ok.
146152
if (!Lexer::isIdentifier(PreferredName)) {
147153
DiagEngine.diagnose(SourceLoc(), diag::invalid_name, PreferredName);
@@ -300,4 +306,5 @@ bool RefactoringActionExtractFunction::performChange() {
300306
EditConsumer.accept(SM, RangeInfo.ContentRange, CallStr, NotableCallRegions);
301307

302308
return false;
309+
#endif
303310
}

0 commit comments

Comments
 (0)