@@ -46,32 +46,15 @@ extension DocumentationLanguageService {
46
46
catalogURL: catalogURL
47
47
)
48
48
case . markdown:
49
- if case let . symbol( symbolName) = MarkdownTitleFinder . find ( parsing: snapshot. text) {
50
- if let moduleName, symbolName == moduleName {
51
- // This is a page representing the module itself.
52
- // Create a dummy symbol graph and tell SwiftDocC to convert the module name.
53
- let emptySymbolGraph = String (
54
- data: try JSONEncoder ( ) . encode (
55
- SymbolGraph (
56
- metadata: SymbolGraph . Metadata (
57
- formatVersion: SymbolGraph . SemanticVersion ( major: 0 , minor: 5 , patch: 0 ) ,
58
- generator: " SourceKit-LSP "
59
- ) ,
60
- module: SymbolGraph . Module ( name: moduleName, platform: SymbolGraph . Platform ( ) ) ,
61
- symbols: [ ] ,
62
- relationships: [ ]
63
- )
64
- ) ,
65
- encoding: . utf8
66
- )
67
- return try await documentationManager. renderDocCDocumentation (
68
- symbolUSR: moduleName,
69
- symbolGraph: emptySymbolGraph,
70
- markupFile: snapshot. text,
71
- moduleName: moduleName,
72
- catalogURL: catalogURL
73
- )
74
- }
49
+ guard case . symbol( let symbolName) = MarkdownTitleFinder . find ( parsing: snapshot. text) else {
50
+ // This is an article that can be rendered on its own
51
+ return try await documentationManager. renderDocCDocumentation (
52
+ markupFile: snapshot. text,
53
+ moduleName: moduleName,
54
+ catalogURL: catalogURL
55
+ )
56
+ }
57
+ guard let moduleName, symbolName == moduleName else {
75
58
// This is a symbol extension page. Find the symbol so that we can include it in the request.
76
59
guard let index = workspace. index ( checkedFor: . deletedFiles) else {
77
60
throw ResponseError . requestFailed ( doccDocumentationError: . indexNotAvailable)
@@ -115,8 +98,25 @@ extension DocumentationLanguageService {
115
98
catalogURL: catalogURL
116
99
)
117
100
}
118
- // This is an article that can be rendered on its own
101
+ // This is a page representing the module itself.
102
+ // Create a dummy symbol graph and tell SwiftDocC to convert the module name.
103
+ let emptySymbolGraph = String (
104
+ data: try JSONEncoder ( ) . encode (
105
+ SymbolGraph (
106
+ metadata: SymbolGraph . Metadata (
107
+ formatVersion: SymbolGraph . SemanticVersion ( major: 0 , minor: 5 , patch: 0 ) ,
108
+ generator: " SourceKit-LSP "
109
+ ) ,
110
+ module: SymbolGraph . Module ( name: moduleName, platform: SymbolGraph . Platform ( ) ) ,
111
+ symbols: [ ] ,
112
+ relationships: [ ]
113
+ )
114
+ ) ,
115
+ encoding: . utf8
116
+ )
119
117
return try await documentationManager. renderDocCDocumentation (
118
+ symbolUSR: moduleName,
119
+ symbolGraph: emptySymbolGraph,
120
120
markupFile: snapshot. text,
121
121
moduleName: moduleName,
122
122
catalogURL: catalogURL
@@ -128,20 +128,18 @@ extension DocumentationLanguageService {
128
128
}
129
129
130
130
struct MarkdownTitleFinder : MarkupVisitor {
131
- public typealias Result = Title ?
132
-
133
131
public enum Title {
134
132
case plainText( String )
135
133
case symbol( String )
136
134
}
137
135
138
- public static func find( parsing text: String ) -> Result {
136
+ public static func find( parsing text: String ) -> Title ? {
139
137
let document = Markdown . Document ( parsing: text, options: [ . parseSymbolLinks] )
140
138
var visitor = MarkdownTitleFinder ( )
141
139
return visitor. visit ( document)
142
140
}
143
141
144
- public mutating func defaultVisit( _ markup: any Markup ) -> Result {
142
+ public mutating func defaultVisit( _ markup: any Markup ) -> Title ? {
145
143
for child in markup. children {
146
144
if let value = visit ( child) {
147
145
return value
@@ -150,7 +148,7 @@ struct MarkdownTitleFinder: MarkupVisitor {
150
148
return nil
151
149
}
152
150
153
- public mutating func visitHeading( _ heading: Heading ) -> Result {
151
+ public mutating func visitHeading( _ heading: Heading ) -> Title ? {
154
152
guard heading. level == 1 else {
155
153
return nil
156
154
}
0 commit comments