From 7df5441647a176c2739435a7285f201ff1c90384 Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Fri, 27 Dec 2024 07:58:20 -0500 Subject: [PATCH] Introduce plain text semantic styles, remove default Xcode font --- Sources/ThemePark/Style.swift | 2 +- Sources/ThemePark/SyntaxSpecifier.swift | 13 ++++++++++--- Sources/ThemePark/XcodeTheme.swift | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Sources/ThemePark/Style.swift b/Sources/ThemePark/Style.swift index 74a3e68..f6f2bf8 100644 --- a/Sources/ThemePark/Style.swift +++ b/Sources/ThemePark/Style.swift @@ -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)) } diff --git a/Sources/ThemePark/SyntaxSpecifier.swift b/Sources/ThemePark/SyntaxSpecifier.swift index a20176e..c98e201 100644 --- a/Sources/ThemePark/SyntaxSpecifier.swift +++ b/Sources/ThemePark/SyntaxSpecifier.swift @@ -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?) @@ -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), @@ -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 } } diff --git a/Sources/ThemePark/XcodeTheme.swift b/Sources/ThemePark/XcodeTheme.swift index 0dd8eee..0eb4fbf 100644 --- a/Sources/ThemePark/XcodeTheme.swift +++ b/Sources/ThemePark/XcodeTheme.swift @@ -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 { @@ -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) } @@ -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")