Skip to content

Commit f81cb38

Browse files
committed
use separate markdown syntax highlight code to represent argument labels in signatures
1 parent 776f54a commit f81cb38

File tree

6 files changed

+16
-23
lines changed

6 files changed

+16
-23
lines changed

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Context.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ extension MarkdownBytecode
5555
case `class`
5656
case type
5757
case `typealias`
58+
/// Argument label, used to line-break long function signatures.
59+
/// New in 8.0.
60+
case label
5861

5962
// Section elements.
6063
case parameters = 0xC0

Sources/MarkdownRendering/MarkdownElementContext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extension MarkdownElementContext
9292
case .identifier: self = .highlight(.identifier, attributes: &attributes)
9393
case .interpolation: self = .highlight(.interpolation, attributes: &attributes)
9494
case .keyword: self = .highlight(.keyword, attributes: &attributes)
95+
case .label: self = .highlight(.label, attributes: &attributes)
9596
case .literalNumber: self = .highlight(.literalNumber, attributes: &attributes)
9697
case .literalString: self = .highlight(.literalString, attributes: &attributes)
9798
case .magic: self = .highlight(.magic, attributes: &attributes)

Sources/MarkdownRendering/MarkdownSyntaxHighlight.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum MarkdownSyntaxHighlight:String, Equatable, Hashable, Sendable
99
case identifier = "syntax-identifier"
1010
case interpolation = "syntax-interpolation"
1111
case keyword = "syntax-keyword"
12+
case label = "syntax-label"
1213
case literalNumber = "syntax-literal-number"
1314
case literalString = "syntax-literal-string"
1415
case magic = "syntax-magic"

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ extension Signature<Symbol.Decl>.Abridged
1010
{
1111
for fragment:Signature.Fragment in fragments
1212
{
13-
if fragment.nominal
13+
switch (fragment.color, fragment.spelling)
1414
{
15+
case (.identifier, _),
16+
(.keyword, "init"),
17+
(.keyword, "deinit"),
18+
(.keyword, "subscript"):
1519
$0[.identifier] = fragment.spelling
16-
}
17-
else
18-
{
20+
21+
case (.label, _):
22+
$0[.label] = fragment.spelling
23+
24+
case _:
1925
$0 += fragment.spelling
2026
}
2127
}

Sources/SymbolGraphParts/Signatures/Signature.Fragment.Color.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension Signature.Fragment.Color
6060
case .binding: return .binding
6161
case .identifier: return .identifier
6262
case .keyword: return .keyword
63-
case .label: return .identifier
63+
case .label: return .label
6464
case .text: return nil
6565
case .typeIdentifier: return .type
6666
case .typeParameter: return .typealias

Sources/SymbolGraphParts/Signatures/Signature.Fragment.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ extension Signature<Symbol.Decl>
2424
}
2525
}
2626
extension Signature.Fragment
27-
{
28-
var nominal:Bool
29-
{
30-
switch (self.color, self.spelling)
31-
{
32-
case (.label, _),
33-
(.identifier, _),
34-
(.keyword, "init"),
35-
(.keyword, "deinit"),
36-
(.keyword, "subscript"):
37-
return true
38-
39-
case _:
40-
return false
41-
}
42-
}
43-
}
44-
extension Signature.Fragment
4527
{
4628
func spelled(_ spelling:__owned String) -> Self
4729
{

0 commit comments

Comments
 (0)