-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New RootLanguage type to make this all slightly safer
- Loading branch information
1 parent
913c69e
commit 8171a41
Showing
6 changed files
with
81 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Foundation | ||
import UniformTypeIdentifiers | ||
|
||
/// Describes a document root language. | ||
/// | ||
/// This type must also be compiled into EditIntents, because the AppIntent infrastructure depends on having the type visible within the module. | ||
public enum RootLanguage: Hashable, CaseIterable, Sendable { | ||
case go | ||
case markdown | ||
case ocaml | ||
case swift | ||
|
||
var typeIdentifier: UTType { | ||
switch self { | ||
case .go: .goSource | ||
case .markdown: .markdown | ||
case .ocaml: .ocamlSource | ||
case .swift: .swiftSource | ||
} | ||
} | ||
} | ||
|
||
extension RootLanguage: RawRepresentable { | ||
public static func normalizeLanguageName(_ identifier: String) -> String { | ||
identifier.lowercased().replacingOccurrences(of: "-", with: "_") | ||
} | ||
|
||
public init?(rawValue: String) { | ||
switch Self.normalizeLanguageName(rawValue) { | ||
case "go": | ||
self = .go | ||
case "markdown": | ||
self = .markdown | ||
case "ocaml": | ||
self = .ocaml | ||
case "swift": | ||
self = .swift | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
public var rawValue: String { | ||
switch self { | ||
case .go: | ||
"Go" | ||
case .markdown: | ||
"Markdown" | ||
case .ocaml: | ||
"OCaml" | ||
case .swift: | ||
"Swift" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters