Skip to content

Commit 4bbff3d

Browse files
committed
Update SKDResponseDictionary subscript to actually return optionals
1 parent a3fbc2d commit 4bbff3d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Sources/SourceKitD/SKDResponseDictionary.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,31 @@ public final class SKDResponseDictionary {
3030
return sourcekitd.api.variant_dictionary_get_string(dict, key).map(String.init(cString:))
3131
}
3232
public subscript(key: sourcekitd_uid_t?) -> Int? {
33-
return Int(sourcekitd.api.variant_dictionary_get_int64(dict, key))
33+
let value = sourcekitd.api.variant_dictionary_get_value(dict, key)
34+
if sourcekitd.api.variant_get_type(value) == SOURCEKITD_VARIANT_TYPE_INT64 {
35+
return Int(sourcekitd.api.variant_int64_get_value(value))
36+
} else {
37+
return nil
38+
}
3439
}
3540
public subscript(key: sourcekitd_uid_t?) -> Bool? {
36-
return sourcekitd.api.variant_dictionary_get_bool(dict, key)
41+
let value = sourcekitd.api.variant_dictionary_get_value(dict, key)
42+
if sourcekitd.api.variant_get_type(value) == SOURCEKITD_VARIANT_TYPE_BOOL {
43+
return sourcekitd.api.variant_bool_get_value(value)
44+
} else {
45+
return nil
46+
}
3747
}
3848
public subscript(key: sourcekitd_uid_t?) -> sourcekitd_uid_t? {
3949
return sourcekitd.api.variant_dictionary_get_uid(dict, key)
4050
}
4151
public subscript(key: sourcekitd_uid_t?) -> SKDResponseArray? {
42-
return SKDResponseArray(sourcekitd.api.variant_dictionary_get_value(dict, key), response: resp)
52+
let value = sourcekitd.api.variant_dictionary_get_value(dict, key)
53+
if sourcekitd.api.variant_get_type(value) == SOURCEKITD_VARIANT_TYPE_ARRAY {
54+
return SKDResponseArray(value, response: resp)
55+
} else {
56+
return nil
57+
}
4358
}
4459
}
4560

0 commit comments

Comments
 (0)