From fb46d62d4b52dad375cf2540c767552e8d38f54e Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 20 Dec 2017 18:27:53 +0100 Subject: [PATCH] Remove stream API from NvimMsgPack --- .../NvimMsgPack.xcodeproj/project.pbxproj | 6 - NvimMsgPack/NvimMsgPack/NvimApi.swift | 36 - NvimMsgPack/NvimMsgPack/NvimApiMethods.swift | 2684 ----------------- NvimView/NvimView/NvimApiExtension.swift | 22 - NvimView/NvimView/NvimView.swift | 1 - bin/generate_api_methods.py | 89 - 6 files changed, 2838 deletions(-) diff --git a/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj b/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj index dcea3ecd..564b752b 100644 --- a/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj +++ b/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj @@ -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 = ""; }; 4B9E33821FCB47F900E0C4BC /* ResultProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultProtocol.swift; sourceTree = ""; }; 4BC8843F1FDC6A45000E95A2 /* NvimMsgPack.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = NvimMsgPack.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 4BEB11921FE52BF6005D4FF6 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = ../Carthage/Build/Mac/RxSwift.framework; sourceTree = ""; }; /* 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"; diff --git a/NvimMsgPack/NvimMsgPack/NvimApi.swift b/NvimMsgPack/NvimMsgPack/NvimApi.swift index ce08e2f9..f792fed4 100644 --- a/NvimMsgPack/NvimMsgPack/NvimApi.swift +++ b/NvimMsgPack/NvimMsgPack/NvimApi.swift @@ -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 { - let single = Single.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? { diff --git a/NvimMsgPack/NvimMsgPack/NvimApiMethods.swift b/NvimMsgPack/NvimMsgPack/NvimApiMethods.swift index e10e8771..818a18b6 100644 --- a/NvimMsgPack/NvimMsgPack/NvimApiMethods.swift +++ b/NvimMsgPack/NvimMsgPack/NvimApiMethods.swift @@ -2,7 +2,6 @@ // See bin/generate_api_methods.py import MsgPackRpc -import RxSwift extension NvimApi { @@ -2792,2686 +2791,3 @@ extension Dictionary { } } -extension StreamApi { - - public func bufLineCount( - buffer: NvimApi.Buffer - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - ] - let response = self.session.rpc(method: "nvim_buf_line_count", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufGetLines( - buffer: NvimApi.Buffer, - start: Int, - end: Int, - strict_indexing: Bool - ) -> Single<[String]> { - - let single = Single<[String]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .int(Int64(start)), - .int(Int64(end)), - .bool(strict_indexing), - ] - let response = self.session.rpc(method: "nvim_buf_get_lines", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in v.stringValue })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufSetLines( - buffer: NvimApi.Buffer, - start: Int, - end: Int, - strict_indexing: Bool, - replacement: [String], - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .int(Int64(start)), - .int(Int64(end)), - .bool(strict_indexing), - .array(replacement.map { .string($0) }), - ] - let response = self.session.rpc(method: "nvim_buf_set_lines", 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 - } - - public func bufGetVar( - buffer: NvimApi.Buffer, - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_buf_get_var", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufGetChangedtick( - buffer: NvimApi.Buffer - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - ] - let response = self.session.rpc(method: "nvim_buf_get_changedtick", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufGetKeymap( - buffer: NvimApi.Buffer, - mode: String - ) -> Single<[Dictionary]> { - - let single = Single<[Dictionary]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(mode), - ] - let response = self.session.rpc(method: "nvim_buf_get_keymap", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackArrayDictToSwift(value.arrayValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufSetVar( - buffer: NvimApi.Buffer, - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_buf_set_var", 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 - } - - public func bufDelVar( - buffer: NvimApi.Buffer, - name: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_buf_del_var", 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 - } - - public func bufGetOption( - buffer: NvimApi.Buffer, - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_buf_get_option", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufSetOption( - buffer: NvimApi.Buffer, - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_buf_set_option", 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 - } - - public func bufGetName( - buffer: NvimApi.Buffer - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - ] - let response = self.session.rpc(method: "nvim_buf_get_name", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.stringValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufSetName( - buffer: NvimApi.Buffer, - name: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_buf_set_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 - } - - public func bufIsValid( - buffer: NvimApi.Buffer - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - ] - let response = self.session.rpc(method: "nvim_buf_is_valid", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.boolValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufGetMark( - buffer: NvimApi.Buffer, - name: String - ) -> Single<[Int]> { - - let single = Single<[Int]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_buf_get_mark", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in (v.integerValue == nil ? nil : Int(v.integerValue!)) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufAddHighlight( - buffer: NvimApi.Buffer, - src_id: Int, - hl_group: String, - line: Int, - col_start: Int, - col_end: Int - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .int(Int64(src_id)), - .string(hl_group), - .int(Int64(line)), - .int(Int64(col_start)), - .int(Int64(col_end)), - ] - let response = self.session.rpc(method: "nvim_buf_add_highlight", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func bufClearHighlight( - buffer: NvimApi.Buffer, - src_id: Int, - line_start: Int, - line_end: Int, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - .int(Int64(src_id)), - .int(Int64(line_start)), - .int(Int64(line_end)), - ] - let response = self.session.rpc(method: "nvim_buf_clear_highlight", 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 - } - - public func tabpageListWins( - tabpage: NvimApi.Tabpage - ) -> Single<[NvimApi.Window]> { - - let single = Single<[NvimApi.Window]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - ] - let response = self.session.rpc(method: "nvim_tabpage_list_wins", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in NvimApi.Window(v) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func tabpageGetVar( - tabpage: NvimApi.Tabpage, - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_tabpage_get_var", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func tabpageSetVar( - tabpage: NvimApi.Tabpage, - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_tabpage_set_var", 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 - } - - public func tabpageDelVar( - tabpage: NvimApi.Tabpage, - name: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_tabpage_del_var", 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 - } - - public func tabpageGetWin( - tabpage: NvimApi.Tabpage - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - ] - let response = self.session.rpc(method: "nvim_tabpage_get_win", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Window(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func tabpageGetNumber( - tabpage: NvimApi.Tabpage - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - ] - let response = self.session.rpc(method: "nvim_tabpage_get_number", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func tabpageIsValid( - tabpage: NvimApi.Tabpage - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - ] - let response = self.session.rpc(method: "nvim_tabpage_is_valid", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.boolValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func uiAttach( - width: Int, - height: Int, - options: Dictionary, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(width)), - .int(Int64(height)), - .map(options.mapToDict({ (Value.string($0), $1) })), - ] - let response = self.session.rpc(method: "nvim_ui_attach", 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 - } - - public func uiDetach( - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_ui_detach", 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 - } - - public func uiTryResize( - width: Int, - height: Int, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(width)), - .int(Int64(height)), - ] - let response = self.session.rpc(method: "nvim_ui_try_resize", 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 - } - - public func uiSetOption( - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_ui_set_option", 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 - } - - public func command( - command: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(command), - ] - let response = self.session.rpc(method: "nvim_command", 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 - } - - public func getHlByName( - name: String, - rgb: Bool - ) -> Single> { - - let single = Single>.create { single in - let params: [NvimApi.Value] = [ - .string(name), - .bool(rgb), - ] - let response = self.session.rpc(method: "nvim_get_hl_by_name", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackDictToSwift(value.dictionaryValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getHlById( - hl_id: Int, - rgb: Bool - ) -> Single> { - - let single = Single>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(hl_id)), - .bool(rgb), - ] - let response = self.session.rpc(method: "nvim_get_hl_by_id", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackDictToSwift(value.dictionaryValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func feedkeys( - keys: String, - mode: String, - escape_csi: Bool, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(keys), - .string(mode), - .bool(escape_csi), - ] - let response = self.session.rpc(method: "nvim_feedkeys", 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 - } - - public func input( - keys: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(keys), - ] - let response = self.session.rpc(method: "nvim_input", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func replaceTermcodes( - str: String, - from_part: Bool, - do_lt: Bool, - special: Bool - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(str), - .bool(from_part), - .bool(do_lt), - .bool(special), - ] - let response = self.session.rpc(method: "nvim_replace_termcodes", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.stringValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func commandOutput( - str: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(str), - ] - let response = self.session.rpc(method: "nvim_command_output", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.stringValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func eval( - expr: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(expr), - ] - let response = self.session.rpc(method: "nvim_eval", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func callFunction( - fname: String, - args: NvimApi.Value - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(fname), - args, - ] - let response = self.session.rpc(method: "nvim_call_function", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func executeLua( - code: String, - args: NvimApi.Value - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(code), - args, - ] - let response = self.session.rpc(method: "nvim_execute_lua", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func strwidth( - text: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(text), - ] - let response = self.session.rpc(method: "nvim_strwidth", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func listRuntimePaths( - ) -> Single<[String]> { - - let single = Single<[String]>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_list_runtime_paths", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in v.stringValue })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setCurrentDir( - dir: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(dir), - ] - let response = self.session.rpc(method: "nvim_set_current_dir", 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 - } - - public func getCurrentLine( - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_current_line", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.stringValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setCurrentLine( - line: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(line), - ] - let response = self.session.rpc(method: "nvim_set_current_line", 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 - } - - public func delCurrentLine( - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_del_current_line", 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 - } - - public func getVar( - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - ] - let response = self.session.rpc(method: "nvim_get_var", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setVar( - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_set_var", 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 - } - - public func delVar( - name: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - ] - let response = self.session.rpc(method: "nvim_del_var", 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 - } - - public func getVvar( - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - ] - let response = self.session.rpc(method: "nvim_get_vvar", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getOption( - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - ] - let response = self.session.rpc(method: "nvim_get_option", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setOption( - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_set_option", 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 - } - - public func outWrite( - str: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(str), - ] - let response = self.session.rpc(method: "nvim_out_write", 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 - } - - public func errWrite( - str: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(str), - ] - let response = self.session.rpc(method: "nvim_err_write", 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 - } - - public func errWriteln( - str: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(str), - ] - let response = self.session.rpc(method: "nvim_err_writeln", 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 - } - - public func listBufs( - ) -> Single<[NvimApi.Buffer]> { - - let single = Single<[NvimApi.Buffer]>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_list_bufs", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in NvimApi.Buffer(v) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getCurrentBuf( - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_current_buf", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Buffer(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setCurrentBuf( - buffer: NvimApi.Buffer, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(buffer.handle)), - ] - let response = self.session.rpc(method: "nvim_set_current_buf", 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 - } - - public func listWins( - ) -> Single<[NvimApi.Window]> { - - let single = Single<[NvimApi.Window]>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_list_wins", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in NvimApi.Window(v) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getCurrentWin( - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_current_win", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Window(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setCurrentWin( - window: NvimApi.Window, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_set_current_win", 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 - } - - public func listTabpages( - ) -> Single<[NvimApi.Tabpage]> { - - let single = Single<[NvimApi.Tabpage]>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_list_tabpages", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in NvimApi.Tabpage(v) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getCurrentTabpage( - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_current_tabpage", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Tabpage(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func setCurrentTabpage( - tabpage: NvimApi.Tabpage, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(tabpage.handle)), - ] - let response = self.session.rpc(method: "nvim_set_current_tabpage", 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 - } - - public func subscribe( - event: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(event), - ] - let response = self.session.rpc(method: "nvim_subscribe", 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 - } - - public func unsubscribe( - event: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(event), - ] - let response = self.session.rpc(method: "nvim_unsubscribe", 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 - } - - public func getColorByName( - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .string(name), - ] - let response = self.session.rpc(method: "nvim_get_color_by_name", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getColorMap( - ) -> Single> { - - let single = Single>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_color_map", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackDictToSwift(value.dictionaryValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getMode( - ) -> Single> { - - let single = Single>.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_mode", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackDictToSwift(value.dictionaryValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getKeymap( - mode: String - ) -> Single<[Dictionary]> { - - let single = Single<[Dictionary]>.create { single in - let params: [NvimApi.Value] = [ - .string(mode), - ] - let response = self.session.rpc(method: "nvim_get_keymap", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (msgPackArrayDictToSwift(value.arrayValue)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func getApiInfo( - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - - ] - let response = self.session.rpc(method: "nvim_get_api_info", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func callAtomic( - calls: NvimApi.Value - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - calls, - ] - let response = self.session.rpc(method: "nvim_call_atomic", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winGetBuf( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_buf", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Buffer(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winGetCursor( - window: NvimApi.Window - ) -> Single<[Int]> { - - let single = Single<[Int]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_cursor", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in (v.integerValue == nil ? nil : Int(v.integerValue!)) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winSetCursor( - window: NvimApi.Window, - pos: [Int], - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .array(pos.map { .int(Int64($0)) }), - ] - let response = self.session.rpc(method: "nvim_win_set_cursor", 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 - } - - public func winGetHeight( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_height", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winSetHeight( - window: NvimApi.Window, - height: Int, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .int(Int64(height)), - ] - let response = self.session.rpc(method: "nvim_win_set_height", 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 - } - - public func winGetWidth( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_width", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winSetWidth( - window: NvimApi.Window, - width: Int, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .int(Int64(width)), - ] - let response = self.session.rpc(method: "nvim_win_set_width", 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 - } - - public func winGetVar( - window: NvimApi.Window, - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_win_get_var", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winSetVar( - window: NvimApi.Window, - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_win_set_var", 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 - } - - public func winDelVar( - window: NvimApi.Window, - name: String, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_win_del_var", 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 - } - - public func winGetOption( - window: NvimApi.Window, - name: String - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .string(name), - ] - let response = self.session.rpc(method: "nvim_win_get_option", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (Optional(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winSetOption( - window: NvimApi.Window, - name: String, - value: NvimApi.Value, - expectsReturnValue: Bool = true - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - .string(name), - value, - ] - let response = self.session.rpc(method: "nvim_win_set_option", 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 - } - - public func winGetPosition( - window: NvimApi.Window - ) -> Single<[Int]> { - - let single = Single<[Int]>.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_position", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.arrayValue?.flatMap({ v in (v.integerValue == nil ? nil : Int(v.integerValue!)) })) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winGetTabpage( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_tabpage", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (NvimApi.Tabpage(value)) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winGetNumber( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_get_number", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = ((value.integerValue == nil ? nil : Int(value.integerValue!))) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - - public func winIsValid( - window: NvimApi.Window - ) -> Single { - - let single = Single.create { single in - let params: [NvimApi.Value] = [ - .int(Int64(window.handle)), - ] - let response = self.session.rpc(method: "nvim_win_is_valid", params: params, expectsReturnValue: true) - let disposable = Disposables.create() - - guard let value = response.value else { - single(.error(response.error!)) - return disposable - } - - guard let result = (value.boolValue) else { - single(.error(response.error!)) - return disposable - } - - single(.success(result)) - return disposable - } - - if let scheduler = self.scheduler { - return single.subscribeOn(scheduler) - } - - return single - } - -} - diff --git a/NvimView/NvimView/NvimApiExtension.swift b/NvimView/NvimView/NvimApiExtension.swift index 052a22f3..98c07e4e 100644 --- a/NvimView/NvimView/NvimApiExtension.swift +++ b/NvimView/NvimView/NvimApiExtension.swift @@ -35,28 +35,6 @@ extension NvimApi { } } -extension StreamApi { - - public func getBufGetInfo( - buffer: NvimApi.Buffer - ) -> Single> { - - 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.self) - } - - return result - } - } -} - func msgPackDictToSwift(_ dict: Dictionary?) -> Dictionary? { return dict?.flatMapToDict { k, v in guard let strKey = k.stringValue else { diff --git a/NvimView/NvimView/NvimView.swift b/NvimView/NvimView/NvimView.swift index 11fa7e55..8e44c246 100644 --- a/NvimView/NvimView/NvimView.swift +++ b/NvimView/NvimView/NvimView.swift @@ -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) diff --git a/bin/generate_api_methods.py b/bin/generate_api_methods.py index 66be455f..516690fd 100755 --- a/bin/generate_api_methods.py +++ b/bin/generate_api_methods.py @@ -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]) - ))