Skip to content

Commit 703ebb6

Browse files
also add sourceOrigin for local protocols without docs
1 parent 6f53e1d commit 703ebb6

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/SymbolGraphGen/Edge.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const ValueDecl *getForeignProtocolRequirement(const ValueDecl *VD, const Module
3636
requirements.pop();
3737
}
3838
}
39+
40+
const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
41+
auto reqs = VD->getSatisfiedProtocolRequirements();
42+
43+
if (!reqs.empty())
44+
return reqs.front();
45+
else
46+
return nullptr;
47+
}
3948
} // end anonymous namespace
4049

4150
void Edge::serialize(llvm::json::OStream &OS) const {
@@ -82,15 +91,19 @@ void Edge::serialize(llvm::json::OStream &OS) const {
8291
if (const auto *ID = Source.getDeclInheritingDocs())
8392
InheritingDecl = ID;
8493

85-
8694
if (!InheritingDecl && Source.getSynthesizedBaseTypeDecl())
8795
InheritingDecl = Source.getSymbolDecl();
8896

8997
if (!InheritingDecl) {
9098
if (const auto *ID = getForeignProtocolRequirement(Source.getSymbolDecl(), &Graph->M))
9199
InheritingDecl = ID;
92100
}
93-
101+
102+
if (!InheritingDecl) {
103+
if (const auto *ID = getProtocolRequirement(Source.getSymbolDecl()))
104+
InheritingDecl = ID;
105+
}
106+
94107
// If our source symbol is a inheriting decl, write in information about
95108
// where it's inheriting docs from.
96109
if (InheritingDecl) {

test/SymbolGraph/Relationships/Synthesized/InheritedDocs.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-DOCS
99
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA
1010
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
11+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER
1112

1213
// RUN: %target-swift-symbolgraph-extract -module-name InheritedDocs -I %t -pretty-print -output-dir %t -skip-inherited-docs
1314
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes CHECK,SKIP
@@ -16,6 +17,7 @@
1617
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-SKIP
1718
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA
1819
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
20+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER
1921

2022
// RUN: %empty-directory(%t)
2123
// RUN: %target-build-swift %s -module-name InheritedDocs -emit-module -emit-module-path %t/InheritedDocs.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -skip-inherited-docs
@@ -60,19 +62,29 @@
6062

6163
// local implementations of a local protocol still need to a relation to that protocol
6264

63-
// LOCAL: "source": "s:13InheritedDocs1SV9localFuncyyF"
65+
// LOCAL: "source": "s:13InheritedDocs1SV9localFuncyyF"
6466
// LOCAL-NEXT: "target": "s:13InheritedDocs1SV"
6567
// LOCAL-NEXT: "sourceOrigin"
6668
// LOCAL-NEXT: "identifier": "s:13InheritedDocs1PP9localFuncyyF"
6769
// LOCAL-NEXT: "displayName": "P.localFunc()"
6870

71+
// ...both with and without docs
72+
73+
// SUPER: "source": "s:13InheritedDocs1SV9superFuncyyF"
74+
// SUPER-NEXT: "target": "s:13InheritedDocs1SV"
75+
// SUPER-NEXT: "sourceOrigin"
76+
// SUPER-NEXT: "identifier": "s:13InheritedDocs1PP9superFuncyyF"
77+
// SUPER-NEXT: "displayName": "P.superFunc()"
78+
6979
/// Protocol P
7080
public protocol P {
7181
/// Some Function
7282
func someFunc()
7383

7484
/// It's a local function!
7585
func localFunc()
86+
87+
func superFunc()
7688
}
7789

7890
public extension P {
@@ -86,4 +98,6 @@ public extension P {
8698

8799
public struct S: P {
88100
public func localFunc() {}
101+
102+
public func superFunc() {}
89103
}

0 commit comments

Comments
 (0)