mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-24 22:33:52 +03:00
Add extension stream method
This commit is contained in:
parent
517e67ceba
commit
3091ee024a
@ -5,6 +5,7 @@
|
||||
|
||||
import Foundation
|
||||
import NvimMsgPack
|
||||
import RxSwift
|
||||
|
||||
extension NvimApi {
|
||||
|
||||
@ -34,6 +35,28 @@ extension NvimApi {
|
||||
}
|
||||
}
|
||||
|
||||
extension StreamApi {
|
||||
|
||||
public func getBufGetInfo(
|
||||
buffer: NvimApi.Buffer
|
||||
) -> Single<Dictionary<String, NvimApi.Value>> {
|
||||
|
||||
let params: [NvimApi.Value] = [
|
||||
.int(Int64(buffer.handle)),
|
||||
]
|
||||
|
||||
return self
|
||||
.rpc(method: "nvim_buf_get_info", params: params, expectsReturnValue: true)
|
||||
.map {
|
||||
guard let result = (msgPackDictToSwift($0.dictionaryValue)) else {
|
||||
throw NvimApi.Error.conversion(type: Dictionary<String, NvimApi.Value>.self)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func msgPackDictToSwift(_ dict: Dictionary<NvimApi.Value, NvimApi.Value>?) -> Dictionary<String, NvimApi.Value>? {
|
||||
return dict?.flatMapToDict { k, v in
|
||||
guard let strKey = k.stringValue else {
|
||||
@ -57,7 +80,7 @@ extension Dictionary {
|
||||
return tuplesToDict(array)
|
||||
}
|
||||
|
||||
fileprivate func tuplesToDict<K:Hashable, V, S:Sequence>(_ sequence: S)
|
||||
fileprivate func tuplesToDict<K: Hashable, V, S: Sequence>(_ sequence: S)
|
||||
-> Dictionary<K, V> where S.Iterator.Element == (K, V) {
|
||||
|
||||
var result = Dictionary<K, V>(minimumCapacity: sequence.underestimatedCount)
|
||||
|
Loading…
Reference in New Issue
Block a user