mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 06:43:24 +03:00
Remove stream API from NvimMsgPack
This commit is contained in:
parent
71c4c35129
commit
fb46d62d4b
@ -15,7 +15,6 @@
|
||||
4B9E33841FCB47F900E0C4BC /* Result.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B9E33801FCB47F900E0C4BC /* Result.h */; };
|
||||
4B9E33851FCB47F900E0C4BC /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9E33811FCB47F900E0C4BC /* Result.swift */; };
|
||||
4B9E33861FCB47F900E0C4BC /* ResultProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9E33821FCB47F900E0C4BC /* ResultProtocol.swift */; };
|
||||
4BEB11931FE52BF6005D4FF6 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BEB11921FE52BF6005D4FF6 /* RxSwift.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@ -30,7 +29,6 @@
|
||||
4B9E33811FCB47F900E0C4BC /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
|
||||
4B9E33821FCB47F900E0C4BC /* ResultProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultProtocol.swift; sourceTree = "<group>"; };
|
||||
4BC8843F1FDC6A45000E95A2 /* NvimMsgPack.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = NvimMsgPack.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
4BEB11921FE52BF6005D4FF6 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = ../Carthage/Build/Mac/RxSwift.framework; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -38,7 +36,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4BEB11931FE52BF6005D4FF6 /* RxSwift.framework in Frameworks */,
|
||||
4B9E33781FCB476D00E0C4BC /* MsgPackRpc.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@ -79,7 +76,6 @@
|
||||
4B9E33771FCB476D00E0C4BC /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BEB11921FE52BF6005D4FF6 /* RxSwift.framework */,
|
||||
4B9E33791FCB476D00E0C4BC /* MsgPackRpc.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
@ -314,7 +310,6 @@
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 252;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../Carthage/Build/Mac";
|
||||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = NvimMsgPack/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
@ -338,7 +333,6 @@
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 252;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../Carthage/Build/Mac";
|
||||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = NvimMsgPack/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
import Foundation
|
||||
import MsgPackRpc
|
||||
import RxSwift
|
||||
|
||||
public class NvimApi {
|
||||
|
||||
@ -84,15 +83,12 @@ public class NvimApi {
|
||||
}
|
||||
}
|
||||
|
||||
public let stream: StreamApi
|
||||
|
||||
public init?(at path: String) {
|
||||
guard let session = Session(at: path) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.session = session
|
||||
self.stream = StreamApi(session: session)
|
||||
}
|
||||
|
||||
public func connect() throws {
|
||||
@ -122,38 +118,6 @@ public class NvimApi {
|
||||
private let session: Session
|
||||
}
|
||||
|
||||
public class StreamApi {
|
||||
|
||||
public var scheduler: SchedulerType?
|
||||
|
||||
public func rpc(method: String, params: [NvimApi.Value], expectsReturnValue: Bool = true) -> Single<NvimApi.Value> {
|
||||
let single = Single<NvimApi.Value>.create { single in
|
||||
let response = self.session.rpc(method: method, params: params, expectsReturnValue: expectsReturnValue)
|
||||
let disposable = Disposables.create()
|
||||
|
||||
guard let value = response.value else {
|
||||
single(.error(response.error!))
|
||||
return disposable
|
||||
}
|
||||
|
||||
single(.success(value))
|
||||
return disposable
|
||||
}
|
||||
|
||||
if let scheduler = self.scheduler {
|
||||
return single.subscribeOn(scheduler)
|
||||
}
|
||||
|
||||
return single
|
||||
}
|
||||
|
||||
init(session: Session) {
|
||||
self.session = session
|
||||
}
|
||||
|
||||
let session: Session
|
||||
}
|
||||
|
||||
class Session {
|
||||
|
||||
var notificationCallback: NvimApi.NotificationCallback? {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,28 +35,6 @@ 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 {
|
||||
|
@ -182,7 +182,6 @@ public class NvimView: NSView,
|
||||
preconditionFailure("Nvim could not be instantiated")
|
||||
}
|
||||
|
||||
nvim.stream.scheduler = self.nvimApiScheduler
|
||||
self.nvim = nvim
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
@ -92,74 +92,11 @@ func_template = Template('''\
|
||||
}
|
||||
''')
|
||||
|
||||
func_stream_template = Template('''\
|
||||
public func ${func_name}(${args}
|
||||
) -> Single<${result_type}> {
|
||||
|
||||
let single = Single<${result_type}>.create { single in
|
||||
let params: [NvimApi.Value] = [
|
||||
${params}
|
||||
]
|
||||
let response = self.session.rpc(method: "${nvim_func_name}", params: params, expectsReturnValue: true)
|
||||
let disposable = Disposables.create()
|
||||
|
||||
guard let value = response.value else {
|
||||
single(.error(response.error!))
|
||||
return disposable
|
||||
}
|
||||
|
||||
guard let result = (${return_value}) else {
|
||||
single(.error(response.error!))
|
||||
return disposable
|
||||
}
|
||||
|
||||
single(.success(result))
|
||||
return disposable
|
||||
}
|
||||
|
||||
if let scheduler = self.scheduler {
|
||||
return single.subscribeOn(scheduler)
|
||||
}
|
||||
|
||||
return single
|
||||
}
|
||||
''')
|
||||
|
||||
void_func_stream_template = Template('''\
|
||||
public func ${func_name}(${args}
|
||||
expectsReturnValue: Bool = true
|
||||
) -> Single<${result_type}> {
|
||||
|
||||
let single = Single<${result_type}>.create { single in
|
||||
let params: [NvimApi.Value] = [
|
||||
${params}
|
||||
]
|
||||
let response = self.session.rpc(method: "${nvim_func_name}", params: params, expectsReturnValue: expectsReturnValue)
|
||||
let disposable = Disposables.create()
|
||||
|
||||
if let error = response.error {
|
||||
single(.error(error))
|
||||
return disposable
|
||||
}
|
||||
|
||||
single(.success(()))
|
||||
return disposable
|
||||
}
|
||||
|
||||
if let scheduler = self.scheduler {
|
||||
return single.subscribeOn(scheduler)
|
||||
}
|
||||
|
||||
return single
|
||||
}
|
||||
''')
|
||||
|
||||
extension_template = Template('''\
|
||||
// Auto generated for nvim version ${version}.
|
||||
// See bin/generate_api_methods.py
|
||||
|
||||
import MsgPackRpc
|
||||
import RxSwift
|
||||
|
||||
extension NvimApi {
|
||||
|
||||
@ -299,13 +236,6 @@ extension Dictionary {
|
||||
''')
|
||||
|
||||
|
||||
extension_stream_template = Template('''\
|
||||
extension StreamApi {
|
||||
|
||||
$body
|
||||
}
|
||||
''')
|
||||
|
||||
def snake_to_camel(snake_str):
|
||||
components = snake_str.split('_')
|
||||
return components[0] + "".join(x.title() for x in components[1:])
|
||||
@ -461,21 +391,6 @@ def parse_function(f):
|
||||
return result
|
||||
|
||||
|
||||
def parse_function_stream(f):
|
||||
args = parse_args(f['parameters']) if f['return_type'] == 'void' else parse_args(f['parameters'])[:-1]
|
||||
template = void_func_stream_template if f['return_type'] == 'void' else func_stream_template
|
||||
result = template.substitute(
|
||||
func_name=snake_to_camel(f['name'][5:]),
|
||||
nvim_func_name=f['name'],
|
||||
args=args,
|
||||
params=parse_params(f['parameters']),
|
||||
result_type=nvim_type_to_swift(f['return_type']),
|
||||
return_value=msgpack_to_swift('value', nvim_type_to_swift(f['return_type']))
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def parse_version(version):
|
||||
return '.'.join([str(v) for v in [version['major'], version['minor'], version['patch']]])
|
||||
|
||||
@ -507,7 +422,3 @@ if __name__ == '__main__':
|
||||
window_type=api['types']['Window']['id'],
|
||||
tabpage_type=api['types']['Tabpage']['id']
|
||||
))
|
||||
|
||||
print(extension_stream_template.substitute(
|
||||
body='\n'.join([parse_function_stream(f) for f in functions])
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user