Skip to content

Commit 5b6becf

Browse files
committed
[SymbolGraph] Omit empty docComment fields
rdar://59500543
1 parent 04c20b8 commit 5b6becf

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,18 @@ void Symbol::serializeRange(size_t InitialIndentation,
162162
}
163163

164164
void Symbol::serializeDocComment(llvm::json::OStream &OS) const {
165+
const auto *DocCommentProvidingDecl =
166+
dyn_cast_or_null<ValueDecl>(
167+
getDocCommentProvidingDecl(VD, /*AllowSerialized=*/true));
168+
if (!DocCommentProvidingDecl) {
169+
DocCommentProvidingDecl = VD;
170+
}
171+
auto RC = DocCommentProvidingDecl->getRawComment(/*SerializedOK=*/true);
172+
if (RC.isEmpty()) {
173+
return;
174+
}
175+
165176
OS.attributeObject("docComment", [&](){
166-
const auto *DocCommentProvidingDecl =
167-
dyn_cast_or_null<ValueDecl>(
168-
getDocCommentProvidingDecl(VD, /*AllowSerialized=*/true));
169-
if (!DocCommentProvidingDecl) {
170-
DocCommentProvidingDecl = VD;
171-
}
172-
auto RC = DocCommentProvidingDecl->getRawComment(/*SerializedOK=*/true);
173177
auto LL = Graph->Ctx.getLineList(RC);
174178
size_t InitialIndentation = LL.getLines().empty()
175179
? 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name NoDocComment -emit-module-path %t/NoDocComment.swiftmodule
3+
// RUN: %target-swift-symbolgraph-extract -module-name NoDocComment -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/NoDocComment.symbols.json
5+
6+
public struct S {}
7+
8+
// CHECK-NOT: docComment

0 commit comments

Comments
 (0)