@@ -28,71 +28,103 @@ fileprivate extension UnifiedSymbolGraph.Symbol {
28
28
}
29
29
}
30
30
31
- internal extension SymbolGraph . Symbol {
32
- func overloadSubheadingFragments( ) -> [ DeclarationFragments . Fragment ] ? {
33
- guard let sourceFragments = self . declarationFragments ?? self . names. subHeading ?? self . names. navigator, !sourceFragments. isEmpty else {
34
- return nil
35
- }
31
+ private func overloadFragments(
32
+ declarationFragments: [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ? ,
33
+ subHeading: [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ? ,
34
+ navigator: [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ? ,
35
+ functionSignature: SymbolGraph . Symbol . FunctionSignature ?
36
+ ) -> [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ? {
37
+ guard let sourceFragments = declarationFragments ?? subHeading ?? navigator, !sourceFragments. isEmpty else {
38
+ return nil
39
+ }
36
40
37
- var simplifiedFragments = [ DeclarationFragments . Fragment] ( )
41
+ var simplifiedFragments : [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] = [ ]
38
42
39
- // In Swift, methods have a keyword as their first token; if the declaration follows that
40
- // pattern then pull that out
43
+ // In Swift, methods have a keyword as their first token; if the declaration follows that
44
+ // pattern then pull that out
41
45
42
- // Sometimes symbols are decorated with attributes or extra keywords in the full declaration.
43
- // In this case, the sub-heading declaration doesn't include those decorations, so pull that
44
- // keyword if it exists
45
- if let firstFragment = self . names . subHeading? . first, firstFragment. kind == . keyword {
46
- simplifiedFragments. append ( firstFragment)
47
- } else if let firstFragment = sourceFragments. first ( where: { $0. kind != . attribute && $0. kind != . text } ) , firstFragment. kind == . keyword {
48
- // If we only have full declaration fragments, still try to skip a leading attribute if possible
49
- simplifiedFragments. append ( firstFragment)
50
- }
46
+ // Sometimes symbols are decorated with attributes or extra keywords in the full declaration.
47
+ // In this case, the sub-heading declaration doesn't include those decorations, so pull that
48
+ // keyword if it exists
49
+ if let firstFragment = subHeading? . first, firstFragment. kind == . keyword {
50
+ simplifiedFragments. append ( firstFragment)
51
+ } else if let firstFragment = sourceFragments. first ( where: { $0. kind != . attribute && $0. kind != . text } ) , firstFragment. kind == . keyword {
52
+ // If we only have full declaration fragments, still try to skip a leading attribute if possible
53
+ simplifiedFragments. append ( firstFragment)
54
+ }
51
55
52
- // Then, look for the first identifier, which should contain the symbol's name, and add that
53
- if let firstIdentifier = sourceFragments. first ( where: { $0. kind == . identifier } ) {
54
- if !simplifiedFragments. isEmpty {
55
- simplifiedFragments. append ( . init( textFragment: " " ) )
56
- }
57
- simplifiedFragments. append ( firstIdentifier)
56
+ // Then, look for the first identifier, which should contain the symbol's name, and add that
57
+ if let firstIdentifier = sourceFragments. first ( where: { $0. kind == . identifier } ) {
58
+ if !simplifiedFragments. isEmpty {
59
+ simplifiedFragments. append ( . init( textFragment: " " ) )
58
60
}
61
+ simplifiedFragments. append ( firstIdentifier)
62
+ }
59
63
60
- // Assumption: All symbols that can be considered "overloads" are written with method
61
- // syntax, including a list of arguments surrounded by parentheses. In Swift symbol graphs,
62
- // method parameters are included in the FunctionSignature mixin, so if that's present we
63
- // use that to parse the data out.
64
-
65
- simplifiedFragments. append ( . init( textFragment: " ( " ) )
66
-
67
- if let functionSignature = self . functionSignature {
68
- for parameter in functionSignature. parameters {
69
- // Scan through the declaration fragments to see whether this parameter's name is
70
- // externally-facing or not.
71
- let fragment : SymbolGraph . Symbol . DeclarationFragments . Fragment
72
- let parameterName = parameter. externalName ?? parameter. name
73
- if let paramNameFragment = sourceFragments. first ( where: { $0. spelling == parameterName && $0. kind == . externalParameter } ) {
74
- fragment = paramNameFragment
75
- } else {
76
- // If not, then insert an underscore for this parameter.
77
- // FIXME: This is a Swift-centric assumption; change this if/when we support C++ overloads
78
- fragment = . init( kind: . externalParameter, spelling: " _ " , preciseIdentifier: nil )
79
- }
80
- simplifiedFragments. append ( fragment)
81
- simplifiedFragments. append ( . init( textFragment: " : " ) )
64
+ // Assumption: All symbols that can be considered "overloads" are written with method
65
+ // syntax, including a list of arguments surrounded by parentheses. In Swift symbol graphs,
66
+ // method parameters are included in the FunctionSignature mixin, so if that's present we
67
+ // use that to parse the data out.
68
+
69
+ simplifiedFragments. append ( . init( textFragment: " ( " ) )
70
+
71
+ if let functionSignature = functionSignature {
72
+ for parameter in functionSignature. parameters {
73
+ // Scan through the declaration fragments to see whether this parameter's name is
74
+ // externally-facing or not.
75
+ let fragment : SymbolGraph . Symbol . DeclarationFragments . Fragment
76
+ let parameterName = parameter. externalName ?? parameter. name
77
+ if let paramNameFragment = sourceFragments. first ( where: { $0. spelling == parameterName && $0. kind == . externalParameter } ) {
78
+ fragment = paramNameFragment
79
+ } else {
80
+ // If not, then insert an underscore for this parameter.
81
+ // FIXME: This is a Swift-centric assumption; change this if/when we support C++ overloads
82
+ fragment = . init( kind: . externalParameter, spelling: " _ " , preciseIdentifier: nil )
82
83
}
83
- } else {
84
- let parameterFragments = sourceFragments. extractFunctionParameters ( )
85
- simplifiedFragments. append ( contentsOf: parameterFragments)
84
+ simplifiedFragments. append ( fragment)
85
+ simplifiedFragments. append ( . init( textFragment: " : " ) )
86
86
}
87
+ } else {
88
+ let parameterFragments = sourceFragments. extractFunctionParameters ( )
89
+ simplifiedFragments. append ( contentsOf: parameterFragments)
90
+ }
91
+
92
+ if simplifiedFragments. last? . kind == . text, var lastFragment = simplifiedFragments. popLast ( ) {
93
+ lastFragment. spelling += " ) "
94
+ simplifiedFragments. append ( lastFragment)
95
+ } else {
96
+ simplifiedFragments. append ( . init( textFragment: " ) " ) )
97
+ }
87
98
88
- if simplifiedFragments. last? . kind == . text, var lastFragment = simplifiedFragments. popLast ( ) {
89
- lastFragment. spelling += " ) "
90
- simplifiedFragments. append ( lastFragment)
91
- } else {
92
- simplifiedFragments. append ( . init( textFragment: " ) " ) )
99
+ return simplifiedFragments
100
+ }
101
+
102
+ internal extension SymbolGraph . Symbol {
103
+ func overloadSubheadingFragments( ) -> [ DeclarationFragments . Fragment ] ? {
104
+ return overloadFragments (
105
+ declarationFragments: self . declarationFragments,
106
+ subHeading: self . names. subHeading,
107
+ navigator: self . names. navigator,
108
+ functionSignature: self . functionSignature)
109
+ }
110
+ }
111
+
112
+ internal extension UnifiedSymbolGraph . Symbol {
113
+ func overloadSubheadingFragments( ) -> [ UnifiedSymbolGraph . Selector : [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ] {
114
+ var fragmentsMap : [ UnifiedSymbolGraph . Selector : [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] ] = [ : ]
115
+
116
+ for selector in self . allSelectors {
117
+ if let fragments = overloadFragments (
118
+ declarationFragments: self . declarationFragments ( selector: selector) ,
119
+ subHeading: self . names [ selector] ? . subHeading,
120
+ navigator: self . names [ selector] ? . navigator,
121
+ functionSignature: self . functionSignature ( selector: selector)
122
+ ) {
123
+ fragmentsMap [ selector] = fragments
124
+ }
93
125
}
94
126
95
- return simplifiedFragments
127
+ return fragmentsMap
96
128
}
97
129
}
98
130
0 commit comments