-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add make command to generate sourcekit type defines.
- Loading branch information
Showing
5 changed files
with
410 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Swift | ||
|
||
// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length | ||
public struct SourceKitDef { | ||
{% for enum in types.all %} | ||
|
||
public enum {{ enum.name }} { | ||
{% for case in enum.cases %}case {{ case.name|lowerFirst }} | ||
{% endfor %} | ||
case unrecognized(String) | ||
|
||
public init(string: String) { | ||
switch string { | ||
{% for case in enum.cases %}case "{{ case.rawValue }}": | ||
self = .{{ case.name|lowerFirst }} | ||
{% endfor %} | ||
default: | ||
self = .unrecognized(string) | ||
} | ||
} | ||
|
||
public var stringRepresentation: String { | ||
switch self { | ||
{% for case in enum.cases %}case .{{ case.name|lowerFirst }}: | ||
return "{{ case.rawValue }}" | ||
{% endfor %} | ||
case let .unrecognized(string): | ||
return string | ||
} | ||
} | ||
} | ||
{% endfor %} | ||
} | ||
|
||
{% for enum in types.all %} | ||
|
||
public extension SourceKitDef.{{ enum.name }} { | ||
public static let count: Int = {{ enum.cases.count }} | ||
} | ||
{% endfor %} |
Oops, something went wrong.