Skip to content

Commit

Permalink
Introduce plain text semantic styles, remove default Xcode font
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Dec 27, 2024
1 parent 24139ad commit 7df5441
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sources/ThemePark/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extension Styling {
}

public func highlightsQueryCaptureStyle(for name: String, context: Query.Context) -> Style {
let specifier = SyntaxSpecifier(highlightsQueryCapture: name) ?? .text
let specifier = SyntaxSpecifier(highlightsQueryCapture: name) ?? .text(nil)

return style(for: .init(key: .syntax(specifier), context: context))
}
Expand Down
13 changes: 10 additions & 3 deletions Sources/ThemePark/SyntaxSpecifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public enum SyntaxSpecifier: Hashable, Sendable, Codable {
case delimiter
}

case text
public enum Text: Hashable, Sendable, Codable, CaseIterable {
case emphasis
case strong
}

case text(Text?)
case invisible
case keyword(Keyword?)
case literal(Literal?)
Expand Down Expand Up @@ -117,8 +122,10 @@ extension SyntaxSpecifier {
"string.escape": .literal(.string(.escape)),
"string.regex": .literal(.regularExpression),
"string.uri": .literal(.string(.uri)),
"text.emphasis": .text(.emphasis),
"text.literal": .literal(.string(nil)),
"text.reference": .context,
"text.strong": .text(.strong),
"text.uri": .literal(.string(.uri)),
"type": .identifier(.type),
"variable": .identifier(.variable),
Expand All @@ -135,14 +142,14 @@ extension SyntaxSpecifier: CaseIterable {
let allOperators = SyntaxSpecifier.Operator.allCases.map { SyntaxSpecifier.operator($0) } + [.operator(nil)]
let allPunctuation = SyntaxSpecifier.Punctuation.allCases.map { SyntaxSpecifier.punctuation($0) } + [.punctuation(nil)]
let allDefinitions = SyntaxSpecifier.Definition.allCases.map { SyntaxSpecifier.definition($0) } + [.definition(nil)]
let allText = SyntaxSpecifier.Text.allCases.map { SyntaxSpecifier.text($0) } + [.text(nil)]

let base: [SyntaxSpecifier] = [
.text,
.invisible,
.context
]

return base + allKeywords + allLiterals + allComments + allIdentifiers + allOperators + allPunctuation + allDefinitions
return base + allText + allKeywords + allLiterals + allComments + allIdentifiers + allOperators + allPunctuation + allDefinitions
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/ThemePark/XcodeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ extension XcodeTheme: Styling {
syntaxColor(for: "xcode.syntax.plain") ?? .fallbackForegroundColor
}

private var fallbackFont: PlatformFont {
syntaxFont(for: "xcode.syntax.plain") ?? PlatformFont.fallbackFont
private var fallbackFont: PlatformFont? {
syntaxFont(for: "xcode.syntax.plain")
}

private var fallbackBackgroundColor: PlatformColor {
Expand All @@ -146,7 +146,7 @@ extension XcodeTheme: Styling {

private func syntaxStyle(for name: String) -> Style {
let color = syntaxColor(for: name) ?? fallbackForegroundColor
let font = syntaxFont(for: name) ?? fallbackFont
let font = syntaxFont(for: name)

return Style(color: color, font: font)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ extension XcodeTheme: Styling {
return syntaxStyle(for: "xcode.syntax.string")
case .syntax(.keyword(_)):
return syntaxStyle(for: "xcode.syntax.keyword")
case .syntax(.text), .gutter(.label):
case .syntax(.text(_)), .gutter(.label):
return syntaxStyle(for: "xcode.syntax.plain")
case .syntax(.identifier(.variable)):
return syntaxStyle(for: "xcode.syntax.identifier.variable")
Expand Down

0 comments on commit 7df5441

Please sign in to comment.