@@ -17,17 +17,12 @@ import sourcekitd
17
17
public class SourceKitdResponse : CustomStringConvertible {
18
18
19
19
public struct Dictionary : CustomStringConvertible , CustomReflectable {
20
- // The lifetime of this sourcekitd_variant_t is tied to the response it came
21
- // from, so keep a reference to the response too.
22
20
private let dict : sourcekitd_variant_t
23
- private let context : SourceKitdResponse
24
21
25
-
26
- public init ( dict: sourcekitd_variant_t , context: SourceKitdResponse ) {
22
+ public init ( dict: sourcekitd_variant_t ) {
27
23
assert ( sourcekitd_variant_get_type ( dict) . rawValue ==
28
24
SOURCEKITD_VARIANT_TYPE_DICTIONARY . rawValue)
29
25
self . dict = dict
30
- self . context = context
31
26
}
32
27
33
28
public func getString( _ key: SourceKitdUID ) -> String {
@@ -52,12 +47,12 @@ public class SourceKitdResponse: CustomStringConvertible {
52
47
53
48
public func getArray( _ key: SourceKitdUID ) -> Array {
54
49
let value = sourcekitd_variant_dictionary_get_value ( dict, key. uid)
55
- return Array ( arr: value, context : context )
50
+ return Array ( arr: value)
56
51
}
57
52
58
53
public func getDictionary( _ key: SourceKitdUID ) -> Dictionary {
59
54
let value = sourcekitd_variant_dictionary_get_value ( dict, key. uid)
60
- return Dictionary ( dict: value, context : context )
55
+ return Dictionary ( dict: value)
61
56
}
62
57
63
58
public func getOptional( _ key: SourceKitdUID ) -> Variant ? {
@@ -66,7 +61,7 @@ public class SourceKitdResponse: CustomStringConvertible {
66
61
SOURCEKITD_VARIANT_TYPE_NULL . rawValue {
67
62
return nil
68
63
}
69
- return Variant ( val: value, context : context )
64
+ return Variant ( val: value)
70
65
}
71
66
72
67
public var description : String {
@@ -79,21 +74,17 @@ public class SourceKitdResponse: CustomStringConvertible {
79
74
}
80
75
81
76
public struct Array : CustomStringConvertible {
82
- // The lifetime of this sourcekitd_variant_t is tied to the response it came
83
- // from, so keep a reference to the response too.
84
77
private let arr : sourcekitd_variant_t
85
- private let context : SourceKitdResponse
86
78
87
79
public var count : Int {
88
80
let count = sourcekitd_variant_array_get_count ( arr)
89
81
return Int ( count)
90
82
}
91
83
92
- public init ( arr: sourcekitd_variant_t , context : SourceKitdResponse ) {
84
+ public init ( arr: sourcekitd_variant_t ) {
93
85
assert ( sourcekitd_variant_get_type ( arr) . rawValue ==
94
86
SOURCEKITD_VARIANT_TYPE_ARRAY . rawValue)
95
87
self . arr = arr
96
- self . context = context
97
88
}
98
89
99
90
public func getString( _ index: Int ) -> String {
@@ -118,21 +109,20 @@ public class SourceKitdResponse: CustomStringConvertible {
118
109
119
110
public func getArray( _ index: Int ) -> Array {
120
111
let value = sourcekitd_variant_array_get_value ( arr, index)
121
- return Array ( arr: value, context : context )
112
+ return Array ( arr: value)
122
113
}
123
114
124
115
public func getDictionary( _ index: Int ) -> Dictionary {
125
116
let value = sourcekitd_variant_array_get_value ( arr, index)
126
- return Dictionary ( dict: value, context : context )
117
+ return Dictionary ( dict: value)
127
118
}
128
119
129
120
public func enumerate( _ applier: ( _ index: Int , _ value: Variant ) -> Bool ) {
130
121
// The block passed to sourcekit_variant_array_apply() does not actually
131
122
// escape, it's synchronous and not called after returning.
132
- let context = self . context
133
123
withoutActuallyEscaping ( applier) { escapingApplier in
134
124
_ = sourcekitd_variant_array_apply ( arr) { ( index, elem) -> Bool in
135
- return escapingApplier ( Int ( index) , Variant ( val: elem, context : context ) )
125
+ return escapingApplier ( Int ( index) , Variant ( val: elem) )
136
126
}
137
127
}
138
128
}
@@ -144,14 +134,10 @@ public class SourceKitdResponse: CustomStringConvertible {
144
134
}
145
135
146
136
public struct Variant : CustomStringConvertible {
147
- // The lifetime of this sourcekitd_variant_t is tied to the response it came
148
- // from, so keep a reference to the response too.
149
137
private let val : sourcekitd_variant_t
150
- fileprivate let context : SourceKitdResponse
151
138
152
- fileprivate init ( val: sourcekitd_variant_t , context : SourceKitdResponse ) {
139
+ fileprivate init ( val: sourcekitd_variant_t ) {
153
140
self . val = val
154
- self . context = context
155
141
}
156
142
157
143
public func getString( ) -> String {
@@ -181,11 +167,11 @@ public class SourceKitdResponse: CustomStringConvertible {
181
167
}
182
168
183
169
public func getArray( ) -> Array {
184
- return Array ( arr: val, context : context )
170
+ return Array ( arr: val)
185
171
}
186
172
187
173
public func getDictionary( ) -> Dictionary {
188
- return Dictionary ( dict: val, context : context )
174
+ return Dictionary ( dict: val)
189
175
}
190
176
191
177
public var description : String {
@@ -196,7 +182,7 @@ public class SourceKitdResponse: CustomStringConvertible {
196
182
private let resp : sourcekitd_response_t
197
183
198
184
public var value : Dictionary {
199
- return Dictionary ( dict: sourcekitd_response_get_value ( resp) , context : self )
185
+ return Dictionary ( dict: sourcekitd_response_get_value ( resp) )
200
186
}
201
187
202
188
/// Copies the raw bytes of the JSON description of this documentation item.
0 commit comments