[Refactoring] Support async for function extraction

Adapt the `ThrowingEntityAnalyzer` to pick up any
`await` keywords and add an `async` to the extracted
function if necessary along with an `await` for its
call.

rdar://72199949
This commit is contained in:
Hamish Knight
2021-05-26 12:40:35 +01:00
parent 137279750b
commit 8d92241ca9
8 changed files with 105 additions and 33 deletions

View File

@@ -1304,7 +1304,9 @@ bool RefactoringActionExtractFunction::performChange() {
}
OS << ")";
if (RangeInfo.ThrowingUnhandledError)
if (RangeInfo.UnhandledEffects.contains(EffectKind::Async))
OS << " async";
if (RangeInfo.UnhandledEffects.contains(EffectKind::Throws))
OS << " " << tok::kw_throws;
bool InsertedReturnType = false;
@@ -1335,6 +1337,8 @@ bool RefactoringActionExtractFunction::performChange() {
if (RangeInfo.UnhandledEffects.contains(EffectKind::Throws))
OS << tok::kw_try << " ";
if (RangeInfo.UnhandledEffects.contains(EffectKind::Async))
OS << "await ";
CallNameOffset = Buffer.size() - ReplaceBegin;
OS << PreferredName << "(";