Skip to content

Commit cc699d3

Browse files
authored
Merge pull request swiftlang#35572 from bnbarham/async-refactorings
[Refactoring] Add async refactorings
2 parents b378c58 + a9073b0 commit cc699d3

File tree

16 files changed

+3015
-135
lines changed

16 files changed

+3015
-135
lines changed

include/swift/AST/DiagnosticsRefactoring.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,23 @@ WARNING(mismatched_rename, none, "the name at the given location cannot be renam
5454

5555
ERROR(no_insert_position, none, "cannot find inserting position", ())
5656

57+
ERROR(missing_callback_arg, none, "cannot refactor as callback closure argument missing", ())
58+
59+
ERROR(mismatched_callback_args, none, "cannot refactor as callback arguments do not match declaration", ())
60+
61+
ERROR(unknown_callback_conditions, none, "cannot refactor complex if conditions", ())
62+
63+
ERROR(mixed_callback_conditions, none, "cannot refactor mixed nil and not-nil conditions", ())
64+
65+
ERROR(callback_multiple_bound_names, none, "cannot refactor when multiple names bound to single declaration, had '%0' and found '%1'", (StringRef, StringRef))
66+
67+
ERROR(callback_with_fallthrough, none, "cannot refactor switch with fallthrough", ())
68+
69+
ERROR(callback_with_default, none, "cannot refactor switch with default case", ())
70+
71+
ERROR(callback_multiple_case_items, none, "cannot refactor switch using a case with multiple items", ())
72+
73+
ERROR(callback_where_case_item, none, "cannot refactor switch using a case with where clause", ())
74+
5775
#define UNDEFINE_DIAGNOSTIC_MACROS
5876
#include "DefineDiagnosticMacros.h"

include/swift/AST/KnownStdlibTypes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,6 @@ KNOWN_STDLIB_TYPE_DECL(KeyedEncodingContainer, NominalTypeDecl, 1)
9191
KNOWN_STDLIB_TYPE_DECL(KeyedDecodingContainer, NominalTypeDecl, 1)
9292
KNOWN_STDLIB_TYPE_DECL(RangeReplaceableCollection, ProtocolDecl, 1)
9393

94+
KNOWN_STDLIB_TYPE_DECL(Result, NominalTypeDecl, 2)
95+
9496
#undef KNOWN_STDLIB_TYPE_DECL

include/swift/IDE/Refactoring.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
137137
llvm::ArrayRef<DiagnosticConsumer*> DiagConsumers);
138138

139139
ArrayRef<RefactoringKind>
140-
collectAvailableRefactorings(SourceFile *SF, ResolvedCursorInfo CursorInfo,
140+
collectAvailableRefactorings(SourceFile *SF,
141+
const ResolvedCursorInfo &CursorInfo,
141142
std::vector<RefactoringKind> &Scratch,
142143
bool ExcludeRename);
143144

include/swift/IDE/RefactoringKinds.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ CURSOR_REFACTORING(MemberwiseInitLocalRefactoring, "Generate Memberwise Initiali
5454

5555
CURSOR_REFACTORING(AddEquatableConformance, "Add Equatable Conformance", add.equatable.conformance)
5656

57+
CURSOR_REFACTORING(ConvertCallToAsyncAlternative, "Convert Call to Async Alternative", convert.call-to-async)
58+
59+
CURSOR_REFACTORING(ConvertToAsync, "Convert Function to Async", convert.func-to-async)
60+
61+
CURSOR_REFACTORING(AddAsyncAlternative, "Add Async Alternative", add.async-alternative)
62+
5763
RANGE_REFACTORING(ExtractExpr, "Extract Expression", extract.expr)
5864

5965
RANGE_REFACTORING(ExtractFunction, "Extract Method", extract.function)

include/swift/IDE/Utils.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ struct ResolvedCursorInfo {
161161
bool IsRef = true;
162162
bool IsKeywordArgument = false;
163163
Type Ty;
164-
DeclContext *DC = nullptr;
165164
Type ContainerType;
166165
Stmt *TrailingStmt = nullptr;
167166
Expr *TrailingExpr = nullptr;
@@ -187,7 +186,6 @@ struct ResolvedCursorInfo {
187186
this->ExtTyRef = ExtTyRef;
188187
this->IsRef = IsRef;
189188
this->Ty = Ty;
190-
this->DC = ValueD->getDeclContext();
191189
this->ContainerType = ContainerType;
192190
}
193191
void setModuleRef(ModuleEntity Mod) {
@@ -549,6 +547,7 @@ class EditorConsumerInsertStream: public raw_ostream {
549547
}
550548
};
551549

550+
/// Outputs replacements as JSON, see `writeEditsInJson`
552551
class SourceEditJsonConsumer : public SourceEditConsumer {
553552
struct Implementation;
554553
Implementation &Impl;
@@ -558,6 +557,24 @@ class SourceEditJsonConsumer : public SourceEditConsumer {
558557
void accept(SourceManager &SM, RegionType RegionType, ArrayRef<Replacement> Replacements) override;
559558
};
560559

560+
/// Outputs replacements to `OS` in the form
561+
/// ```
562+
/// // </path/to/file> startLine:startCol -> endLine:endCol
563+
/// replacement
564+
/// text
565+
///
566+
/// ```
567+
class SourceEditTextConsumer : public SourceEditConsumer {
568+
llvm::raw_ostream &OS;
569+
570+
public:
571+
SourceEditTextConsumer(llvm::raw_ostream &OS);
572+
573+
void accept(SourceManager &SM, RegionType RegionType,
574+
ArrayRef<Replacement> Replacements) override;
575+
};
576+
577+
/// Outputs the rewritten buffer to `OS` with RUN and CHECK lines removed
561578
class SourceEditOutputConsumer : public SourceEditConsumer {
562579
struct Implementation;
563580
Implementation &Impl;

0 commit comments

Comments
 (0)