Skip to content

Commit 6544ba1

Browse files
committed
[SourceKit/DocSupport] Add a field to mark functions that are async
Resolves rdar://72444843
1 parent bb0c6b3 commit 6544ba1

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %empty-directory(%t.mod)
2+
// RUN: %swift -enable-experimental-concurrency -emit-module -o %t.mod/async.swiftmodule %s -parse-as-library -emit-module-doc-path %t.mod/async.swiftdoc
3+
// RUN: %sourcekitd-test -req=doc-info -module async -- -I %t.mod | %FileCheck %s
4+
5+
// REQUIRES: concurrency
6+
7+
public protocol AsyncProto {
8+
func protoAsyncFunc() async
9+
// CHECK: key.usr: "s:5async10AsyncProtoP05protoB4FuncyyYF"
10+
// CHECK-NOT: }
11+
// CHECK: key.is_async: 1
12+
// CHECK: }
13+
func protoNonAsyncFunc()
14+
// CHECK: key.usr: "s:5async10AsyncProtoP08protoNonB4FuncyyF"
15+
// CHECK-NOT: key.is_async: 1
16+
// CHECK: }
17+
}
18+
19+
public struct AsyncStruct: AsyncProto {
20+
public func structAsyncFunc() async { }
21+
// CHECK: key.usr: "s:5async11AsyncStructV06structB4FuncyyYF"
22+
// CHECK-NOT: }
23+
// CHECK: key.is_async: 1
24+
// CHECK: }
25+
public func structNonAsyncFunc() { }
26+
// CHECK: key.usr: "s:5async11AsyncStructV09structNonB4FuncyyF"
27+
// CHECK-NOT: key.is_async: 1
28+
// CHECK: }
29+
30+
public func protoAsyncFunc() async { }
31+
// CHECK: key.usr: "s:5async11AsyncStructV05protoB4FuncyyYF"
32+
// CHECK-NOT: }
33+
// CHECK: key.conforms
34+
// CHECK: {
35+
// CHECK: key.usr: "s:5async10AsyncProtoP05protoB4FuncyyYF"
36+
// CHECK-NOT: }
37+
// CHECK: key.is_async: 1
38+
// CHECK: }
39+
// CHECK: key.is_async: 1
40+
// CHECK: }
41+
public func protoNonAsyncFunc() { }
42+
// CHECK: key.usr: "s:5async11AsyncStructV08protoNonB4FuncyyF"
43+
// CHECK-NOT: key.is_async: 1
44+
// CHECK: }
45+
}
46+
47+
public func topLevelAsyncFunc() async { }
48+
// CHECK: key.usr: "s:5async17topLevelAsyncFuncyyYF"
49+
// CHECK-NOT: }
50+
// CHECK: key.is_async: 1
51+
// CHECK: }
52+
public func topLevelNonAsyncFunc() { }
53+
// CHECK: key.usr: "s:5async20topLevelNonAsyncFuncyyF"
54+
// CHECK-NOT: key.is_async: 1
55+
// CHECK: }
56+

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ struct DocEntityInfo {
495495
bool IsUnavailable = false;
496496
bool IsDeprecated = false;
497497
bool IsOptional = false;
498+
bool IsAsync = false;
498499
swift::Type Ty;
499500
};
500501

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ static bool initDocEntityInfo(const Decl *D,
426426
Info.IsUnavailable = AvailableAttr::isUnavailable(D);
427427
Info.IsDeprecated = D->getAttrs().getDeprecated(D->getASTContext()) != nullptr;
428428
Info.IsOptional = D->getAttrs().hasAttribute<OptionalAttr>();
429+
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
430+
Info.IsAsync = AFD->hasAsync();
431+
}
429432

430433
if (!IsRef) {
431434
llvm::raw_svector_ostream OS(Info.DocComment);

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ void SKDocConsumer::addDocEntityInfoToDict(const DocEntityInfo &Info,
15911591
Elem.set(KeyIsDeprecated, Info.IsDeprecated);
15921592
if (Info.IsOptional)
15931593
Elem.set(KeyIsOptional, Info.IsOptional);
1594+
if (Info.IsAsync)
1595+
Elem.set(KeyIsAsync, Info.IsAsync);
15941596
if (!Info.DocComment.empty())
15951597
Elem.set(KeyDocFullAsXML, Info.DocComment);
15961598
if (!Info.FullyAnnotatedDecl.empty())

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(self, internal_name, external_name):
106106
KEY('IsDeprecated', 'key.is_deprecated'),
107107
KEY('IsUnavailable', 'key.is_unavailable'),
108108
KEY('IsOptional', 'key.is_optional'),
109+
KEY('IsAsync', 'key.is_async'),
109110
KEY('Message', 'key.message'),
110111
KEY('Introduced', 'key.introduced'),
111112
KEY('Deprecated', 'key.deprecated'),

0 commit comments

Comments
 (0)