Skip to content

Commit 2c75cfb

Browse files
committed
[SourceKit] Similar with what we do for module printing, for quick help, elevate the doc-comment from conformances if the decl itself does not have associated doc-comment. rdar://24409720
1 parent 66fb806 commit 2c75cfb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ func goo1(f : FooClass1) {
178178
f.fooFunc1()
179179
}
180180

181+
public protocol P4 {
182+
/// foo1 comment from P4
183+
func foo1()
184+
/// foo2 comment from P4
185+
func foo2()
186+
}
187+
188+
public class C8 : P4 {
189+
public func foo1() {
190+
}
191+
/// foo2 comment from C1
192+
public func foo2() {
193+
}
194+
}
195+
196+
func foo2(f: C8) {
197+
f.foo1()
198+
f.foo2()
199+
}
200+
181201
// RUN: rm -rf %t.tmp
182202
// RUN: mkdir %t.tmp
183203
// RUN: %swiftc_driver -emit-module -o %t.tmp/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift
@@ -623,3 +643,9 @@ func goo1(f : FooClass1) {
623643

624644
// RUN: %sourcekitd-test -req=cursor -pos=178:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK77 %s
625645
// CHECK77-NOT: @warn_unused_result
646+
647+
// RUN: %sourcekitd-test -req=cursor -pos=197:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK78 %s
648+
// RUN: %sourcekitd-test -req=cursor -pos=198:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK79 %s
649+
650+
// CHECK78: foo1 comment from P4
651+
// CHECK79: foo2 comment from C1

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
632632
}
633633
unsigned DocCommentEnd = SS.size();
634634

635+
if (DocCommentEnd == DocCommentBegin) {
636+
if (auto *Req = ASTPrinter::findConformancesWithDocComment(
637+
const_cast<ValueDecl*>(VD))) {
638+
llvm::raw_svector_ostream OS(SS);
639+
ide::getDocumentationCommentAsXML(Req, OS);
640+
}
641+
DocCommentEnd = SS.size();
642+
}
643+
635644
unsigned DeclBegin = SS.size();
636645
{
637646
llvm::raw_svector_ostream OS(SS);

0 commit comments

Comments
 (0)