Skip to content

Commit 2be40ba

Browse files
committed
we were attaching supplements in the wrong order
1 parent 4ab8d62 commit 2be40ba

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Sources/MarkdownSemantics/Markdown.BlockInterpreter.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,26 @@ extension Markdown.BlockInterpreter
8080

8181
default:
8282
// TODO: emit diagnostic.
83+
print("Unknown @Snippet argument: \(argument)")
8384
continue
8485
}
8586
}
8687

8788
guard
88-
let name:String,
89+
let name:String
90+
else
91+
{
92+
// TODO: emit diagnostic.
93+
print("Missing @Snippet name")
94+
return
95+
}
96+
guard
8997
let snippet:Markdown.Snippet = snippets[name]
9098
else
9199
{
92100
// TODO: emit diagnostic.
101+
print("Unknown @Snippet name: '\(name)'")
102+
print("Available snippets: \(snippets.keys.sorted())")
93103
return
94104
}
95105

@@ -102,6 +112,7 @@ extension Markdown.BlockInterpreter
102112
else
103113
{
104114
// TODO: emit diagnostic.
115+
print("Unknown @Snippet slice: '\(slice)'")
105116
}
106117
}
107118
else

Sources/SymbolGraphBuilder/SymbolGraph (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension SymbolGraph
8383
let articles:[[StaticLinker.Article]] = profiler.measure(\.linking)
8484
{
8585
// Calling this is mandatory, even if there are no supplements!
86-
linker.attach(markdown: markdown, snippets: snippets)
86+
linker.attach(snippets: snippets, markdown: markdown)
8787
}
8888

8989
_ = consume markdown

Sources/SymbolGraphLinker/StaticLinker.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,28 +254,29 @@ extension StaticLinker
254254
extension StaticLinker
255255
{
256256
public mutating
257-
func attach(
258-
markdown:[[MarkdownSourceFile]],
259-
snippets:[SwiftSourceFile]) -> [[Article]]
257+
func attach(snippets:[SwiftSourceFile], markdown:[[MarkdownSourceFile]]) -> [[Article]]
260258
{
261-
// Markdown supplements are attached first, because the snippets may reference them.
262-
defer { self.attach(snippets: snippets) }
263-
return self.attach(markdown: markdown)
259+
// We attach snippets first, because they can be referenced by the markdown
260+
// supplements. This works even if the snippet captions contain references to articles,
261+
// because we only eagarly inline snippet captions as markdown AST nodes; codelink
262+
// resolution does not take place until we link the written documentation.
263+
self.snippets = self.attach(snippets: snippets)
264+
return self.attach(markdown: markdown)
264265
}
265266

266267
private mutating
267-
func attach(snippets supplements:[SwiftSourceFile])
268+
func attach(snippets supplements:[SwiftSourceFile]) -> [String: Markdown.Snippet]
268269
{
269270
guard
270271
let swift:Markdown.SwiftLanguage = self.swiftParser
271272
else
272273
{
273-
return
274+
return [:]
274275
}
275276

276277
// Right now we only do one pass over the snippets, since no one should be referencing
277278
// snippets from other snippets.
278-
self.snippets = supplements.reduce(into: [:])
279+
return supplements.reduce(into: [:])
279280
{
280281
let (caption, slices):(String, [Markdown.SnippetSlice]) = swift.parse(
281282
snippet: $1.utf8)
@@ -372,11 +373,9 @@ extension StaticLinker
372373
location: .init(position: .zero, file: file),
373374
text: article.text)
374375

375-
// There is no point in passing the snippets table here, because snippets are not
376-
// attached until after all the markdown supplements have been attached.
377376
let supplement:Supplement = source.parse(
378377
markdownParser: self.markdownParser,
379-
snippetsTable: [:],
378+
snippetsTable: self.snippets,
380379
diagnostics: &self.tables.diagnostics)
381380

382381
guard let headline:Supplement.Headline = supplement.headline

0 commit comments

Comments
 (0)