Skip to content

Commit 1fa4d6a

Browse files
committed
Add make command to generate sourcekit type defines.
1 parent 7e58a61 commit 1fa4d6a

File tree

5 files changed

+410
-2
lines changed

5 files changed

+410
-2
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ docker_test:
8484
docker_test_4:
8585
docker run -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:40 swift test
8686

87+
generate_sourcekit_defines:
88+
clang -E -P Templates/TypeDefs.h -o Templates/SourceKitDef.swift
89+
sourcery --sources Templates/SourceKitDef.swift --templates Templates/AutoEnumNameFix.stencil --output Templates/SourceKitDef.swift
90+
mv Templates/SourceKitDef.swift Source/SourceKittenFramework
91+
8792
# http://irace.me/swift-profiling/
8893
display_compilation_time:
8994
$(BUILD_TOOL) $(XCODEFLAGS) OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" clean build-for-testing | grep -E ^[1-9]{1}[0-9]*.[0-9]+ms | sort -n

Source/SourceKittenFramework/SourceKitDef.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Generated using Sourcery 0.8.0 — https://github.com/krzysztofzablocki/Sourcery
1+
// Generated using Sourcery 0.9.0 — https://github.com/krzysztofzablocki/Sourcery
22
// DO NOT EDIT
33

4-
// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length
4+
55
import Swift
66

7+
// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length
78
public struct SourceKitDef {
89

910
public enum Key {
@@ -1641,6 +1642,7 @@ public struct SourceKitDef {
16411642
}
16421643
}
16431644

1645+
16441646
public extension SourceKitDef.Key {
16451647
public static let count: Int = 134
16461648
}

Templates/AutoEnumNameFix.stencil

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Swift
2+
3+
// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length
4+
public struct SourceKitDef {
5+
{% for enum in types.all %}
6+
7+
public enum {{ enum.name }} {
8+
{% for case in enum.cases %}case {{ case.name|lowerFirst }}
9+
{% endfor %}
10+
case unrecognized(String)
11+
12+
public init(string: String) {
13+
switch string {
14+
{% for case in enum.cases %}case "{{ case.rawValue }}":
15+
self = .{{ case.name|lowerFirst }}
16+
{% endfor %}
17+
default:
18+
self = .unrecognized(string)
19+
}
20+
}
21+
22+
public var stringRepresentation: String {
23+
switch self {
24+
{% for case in enum.cases %}case .{{ case.name|lowerFirst }}:
25+
return "{{ case.rawValue }}"
26+
{% endfor %}
27+
case let .unrecognized(string):
28+
return string
29+
}
30+
}
31+
}
32+
{% endfor %}
33+
}
34+
35+
{% for enum in types.all %}
36+
37+
public extension SourceKitDef.{{ enum.name }} {
38+
public static let count: Int = {{ enum.cases.count }}
39+
}
40+
{% endfor %}

0 commit comments

Comments
 (0)