mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
Add streaming API methods
This commit is contained in:
parent
c8c19fc23e
commit
517e67ceba
@ -15,6 +15,7 @@
|
||||
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 */
|
||||
@ -29,6 +30,7 @@
|
||||
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 */
|
||||
@ -36,6 +38,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4BEB11931FE52BF6005D4FF6 /* RxSwift.framework in Frameworks */,
|
||||
4B9E33781FCB476D00E0C4BC /* MsgPackRpc.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@ -76,6 +79,7 @@
|
||||
4B9E33771FCB476D00E0C4BC /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BEB11921FE52BF6005D4FF6 /* RxSwift.framework */,
|
||||
4B9E33791FCB476D00E0C4BC /* MsgPackRpc.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
@ -310,6 +314,7 @@
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 249;
|
||||
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";
|
||||
@ -333,6 +338,7 @@
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 249;
|
||||
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,6 +5,7 @@
|
||||
|
||||
import Foundation
|
||||
import MsgPackRpc
|
||||
import RxSwift
|
||||
|
||||
public class NvimApi {
|
||||
|
||||
@ -118,6 +119,30 @@ public class NvimApi {
|
||||
private let session: Session
|
||||
}
|
||||
|
||||
public class StreamApi {
|
||||
|
||||
public func rpc(method: String, params: [NvimApi.Value], expectsReturnValue: Bool = true) -> Single<NvimApi.Value> {
|
||||
return 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
|
||||
}
|
||||
}
|
||||
|
||||
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
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
|
||||
import msgpack
|
||||
from string import Template
|
||||
import re
|
||||
@ -91,11 +92,62 @@ func_template = Template('''\
|
||||
}
|
||||
''')
|
||||
|
||||
func_stream_template = Template('''\
|
||||
public func ${func_name}(${args}
|
||||
) -> Single<${result_type}> {
|
||||
|
||||
return 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
|
||||
}
|
||||
}
|
||||
''')
|
||||
|
||||
void_func_stream_template = Template('''\
|
||||
public func ${func_name}(${args}
|
||||
expectsReturnValue: Bool = true
|
||||
) -> Single<${result_type}> {
|
||||
|
||||
return 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
|
||||
}
|
||||
}
|
||||
''')
|
||||
|
||||
extension_template = Template('''\
|
||||
// Auto generated for nvim version ${version}.
|
||||
// See bin/generate_api_methods.py
|
||||
|
||||
import MsgPackRpc
|
||||
import RxSwift
|
||||
|
||||
extension NvimApi {
|
||||
|
||||
@ -235,6 +287,13 @@ 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:])
|
||||
@ -390,6 +449,21 @@ 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']]])
|
||||
|
||||
@ -421,3 +495,7 @@ 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