Skip to content

Commit 6a369f5

Browse files
committed
Fix decoding Array of LSPAnyCodable
1 parent e4c2a3f commit 6a369f5

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Sources/LanguageServerProtocol/SupportTypes/LSPAny.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,38 @@ extension Array: LSPAnyCodable where Element: LSPAnyCodable {
152152
guard case .array(let array) = array else {
153153
return nil
154154
}
155+
155156
var result = [Element]()
156-
for case .dictionary(let editDict) in array {
157-
guard let element = Element.init(fromLSPDictionary: editDict) else {
158-
return nil
157+
for element in array {
158+
switch element {
159+
case .dictionary(let dict):
160+
if let value = Element(fromLSPDictionary: dict) {
161+
result.append(value)
162+
}
163+
case .array(let value):
164+
if let value = value as? [Element] {
165+
result.append(contentsOf: value)
166+
}
167+
case .string(let value):
168+
if let value = value as? Element {
169+
result.append(value)
170+
}
171+
case .int(let value):
172+
if let value = value as? Element {
173+
result.append(value)
174+
}
175+
case .double(let value):
176+
if let value = value as? Element {
177+
result.append(value)
178+
}
179+
case .bool(let value):
180+
if let value = value as? Element {
181+
result.append(value)
182+
}
183+
case .null:
184+
// skip array of null
185+
break
159186
}
160-
result.append(element)
161187
}
162188
self = result
163189
}

0 commit comments

Comments
 (0)