Skip to content

Commit 7dd3046

Browse files
committed
[ASTPrint] Print documentation comments for extensions and subscripts.
1 parent 8659022 commit 7dd3046

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
12631263
}
12641264

12651265
void PrintAST::visitExtensionDecl(ExtensionDecl *decl) {
1266+
printDocumentationComment(decl);
12661267
printAttributes(decl);
12671268
Printer << "extension ";
12681269
recordDeclLoc(decl,
@@ -1922,6 +1923,7 @@ void PrintAST::visitEnumElementDecl(EnumElementDecl *decl) {
19221923
}
19231924

19241925
void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
1926+
printDocumentationComment(decl);
19251927
printAttributes(decl);
19261928
printAccessibility(decl);
19271929
recordDeclLoc(decl,

lib/AST/RawComment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ SingleRawComment::SingleRawComment(StringRef RawText, unsigned StartColumn)
6969

7070
static bool canHaveComment(const Decl *D) {
7171
return !D->hasClangNode() &&
72-
isa<ValueDecl>(D) &&
72+
(isa<ValueDecl>(D) || isa<ExtensionDecl>(D)) &&
7373
!isa<ParamDecl>(D) &&
7474
(!isa<AbstractTypeParamDecl>(D) || isa<AssociatedTypeDecl>(D));
7575
}

test/IDE/print_source_file_interface_2.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ public class MyClass {
99
func doit(x: Int) {}
1010
}
1111

12+
/// This is a very nice extension.
13+
extension MyClass {
14+
15+
/// and a nice subscript.
16+
subscript(i: Int) -> Int { return 0 }
17+
}
18+
1219
// RUN: %target-swift-ide-test -print-swift-file-interface -source-filename %s > %t.out
1320
// RUN: diff -u %s.result %t.out

test/IDE/print_source_file_interface_2.swift.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ public class MyClass {
1010

1111
internal func doit(x: Int)
1212
}
13+
14+
/// This is a very nice extension.
15+
extension MyClass {
16+
17+
/// and a nice subscript.
18+
internal subscript (i: Int) -> Int { get }
19+
}

0 commit comments

Comments
 (0)