Skip to content

Commit 08d8998

Browse files
committed
attempt to work around a bug in SwiftSyntax 510.0.2, and add a test
1 parent 116ef79 commit 08d8998

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

Sources/MarkdownPluginSwift/Signatures/Signature.Abridged (ext).swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,22 @@ extension Signature.Abridged
2020
self.init(utf8: [UInt8].init(string.utf8))
2121
}
2222

23-
@usableFromInline internal
24-
init(utf8:[UInt8])
23+
@usableFromInline
24+
init(utf8:consuming [UInt8])
2525
{
26+
// There seems to be a bug in SwiftSyntax that causes misalignment of source ranges
27+
// when trimming leading trivia from syntax nodes. As a temporary workaround, we
28+
// replace all newline characters with space characters before parsing the source.
29+
for i:Int in utf8.indices
30+
{
31+
switch utf8[i]
32+
{
33+
case 0x0A: utf8[i] = 0x20
34+
case 0x0D: utf8[i] = 0x20
35+
default: continue
36+
}
37+
}
38+
2639
let signature:SignatureSyntax = utf8.withUnsafeBufferPointer { .abridged($0) }
2740
let bytecode:Markdown.Bytecode = .init
2841
{

Sources/MarkdownPluginSwiftTests/Main.Signatures.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,5 +450,38 @@ extension Main.Signatures:TestBattery
450450
<wbr>) rethrows
451451
""")
452452
}
453+
if let tests:TestGroup = tests / "Abridged" / "BackDeployed"
454+
{
455+
let decl:String = """
456+
@backDeployed(before: macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0)
457+
458+
nonisolated func assertIsolated(\
459+
_ message: @autoclosure () -> String = String(), \
460+
file: StaticString = #fileID, \
461+
line: UInt = #line)
462+
"""
463+
464+
let abridged:Signature<Never>.Abridged = .init(decl)
465+
466+
let rendered:HTML = .init { $0 += abridged.bytecode.safe }
467+
let expected:HTML = .init
468+
{
469+
$0 += "nonisolated func "
470+
$0[.span] { $0.class = "xv" } = "assertIsolated"
471+
$0 += "("
472+
$0[.span] { $0.class = "xi" }
473+
$0 += "@autoclosure () -> String, "
474+
$0[.span] { $0.class = "xi" }
475+
$0[.span] { $0.class = "xv" } = "file"
476+
$0 += ": StaticString, "
477+
$0[.span] { $0.class = "xi" }
478+
$0[.span] { $0.class = "xv" } = "line"
479+
$0 += ": UInt"
480+
$0[.wbr]
481+
$0 += ")"
482+
}
483+
484+
tests.expect("\(rendered)" ==? "\(expected)")
485+
}
453486
}
454487
}

0 commit comments

Comments
 (0)