mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-23 19:21:53 +03:00
Merge remote-tracking branch 'origin/pr/1053'
This commit is contained in:
commit
51a4efee34
@ -43,7 +43,7 @@ public extension NvimView {
|
|||||||
let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars)
|
let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars)
|
||||||
: self.vimPlainString(chars)
|
: self.vimPlainString(chars)
|
||||||
|
|
||||||
_ = self.api.input(keys: finalInput).syncValue()
|
_ = self.api.input(keys: finalInput, errWhenBlocked: false).syncValue()
|
||||||
|
|
||||||
self.keyDownDone = true
|
self.keyDownDone = true
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ public extension NvimView {
|
|||||||
|
|
||||||
// try? self.api.feedkeys(keys: self.vimPlainString(text), mode:"m", escape_ks: false)
|
// try? self.api.feedkeys(keys: self.vimPlainString(text), mode:"m", escape_ks: false)
|
||||||
// .wait()
|
// .wait()
|
||||||
_ = self.api.input(keys: self.vimPlainString(text)).syncValue()
|
_ = self.api.input(keys: self.vimPlainString(text), errWhenBlocked: false).syncValue()
|
||||||
|
|
||||||
if self.hasMarkedText() { self._unmarkText() }
|
if self.hasMarkedText() { self._unmarkText() }
|
||||||
self.keyDownDone = true
|
self.keyDownDone = true
|
||||||
@ -125,7 +125,7 @@ public extension NvimView {
|
|||||||
// So we escape as early as possible
|
// So we escape as early as possible
|
||||||
if chars == "\0" {
|
if chars == "\0" {
|
||||||
self.api
|
self.api
|
||||||
.input(keys: self.wrapNamedKeys("Nul"))
|
.input(keys: self.wrapNamedKeys("Nul"), errWhenBlocked: false)
|
||||||
.subscribe(onFailure: { [weak self] error in
|
.subscribe(onFailure: { [weak self] error in
|
||||||
self?.log.error("Error in \(#function): \(error)")
|
self?.log.error("Error in \(#function): \(error)")
|
||||||
})
|
})
|
||||||
@ -138,7 +138,7 @@ public extension NvimView {
|
|||||||
// Also mentioned in MacVim's KeyBindings.plist
|
// Also mentioned in MacVim's KeyBindings.plist
|
||||||
if flags == .control, chars == "6" {
|
if flags == .control, chars == "6" {
|
||||||
self.api
|
self.api
|
||||||
.input(keys: "\u{1e}") // AKA ^^
|
.input(keys: "\u{1e}", errWhenBlocked: false) // AKA ^^
|
||||||
.subscribe(onFailure: { [weak self] error in
|
.subscribe(onFailure: { [weak self] error in
|
||||||
self?.log.error("Error in \(#function): \(error)")
|
self?.log.error("Error in \(#function): \(error)")
|
||||||
})
|
})
|
||||||
@ -149,7 +149,7 @@ public extension NvimView {
|
|||||||
if flags == .control, chars == "2" {
|
if flags == .control, chars == "2" {
|
||||||
// <C-2> should generate \0, escaping as above
|
// <C-2> should generate \0, escaping as above
|
||||||
self.api
|
self.api
|
||||||
.input(keys: self.wrapNamedKeys("Nul"))
|
.input(keys: self.wrapNamedKeys("Nul"), errWhenBlocked: false)
|
||||||
.subscribe(onFailure: { [weak self] error in
|
.subscribe(onFailure: { [weak self] error in
|
||||||
self?.log.error("Error in \(#function): \(error)")
|
self?.log.error("Error in \(#function): \(error)")
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,7 @@ extension NvimView {
|
|||||||
// NvimView.swift
|
// NvimView.swift
|
||||||
try? self.api.run(inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
|
try? self.api.run(inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
|
||||||
.andThen(
|
.andThen(
|
||||||
self.api.getApiInfo()
|
self.api.getApiInfo(errWhenBlocked: false)
|
||||||
.flatMapCompletable { value in
|
.flatMapCompletable { value in
|
||||||
guard let info = value.arrayValue,
|
guard let info = value.arrayValue,
|
||||||
info.count == 2,
|
info.count == 2,
|
||||||
@ -128,7 +128,7 @@ extension NvimView {
|
|||||||
autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter')
|
autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter')
|
||||||
autocmd ColorScheme * call rpcnotify(\(channel), 'autocommand', 'colorscheme', get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
autocmd ColorScheme * call rpcnotify(\(channel), 'autocommand', 'colorscheme', get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
||||||
autocmd VimEnter * call rpcrequest(\(channel), 'vimenter')
|
autocmd VimEnter * call rpcrequest(\(channel), 'vimenter')
|
||||||
""", opts: [:])
|
""", opts: [:], errWhenBlocked: false)
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
.asCompletable()
|
.asCompletable()
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
|
|||||||
private var _characterspacing = NvimView.defaultCharacterspacing
|
private var _characterspacing = NvimView.defaultCharacterspacing
|
||||||
|
|
||||||
private func doSetupForVimenterAndSendResponse(forMsgid msgid: UInt32) {
|
private func doSetupForVimenterAndSendResponse(forMsgid msgid: UInt32) {
|
||||||
self.api.getApiInfo()
|
self.api.getApiInfo(errWhenBlocked: false)
|
||||||
.flatMapCompletable { value in
|
.flatMapCompletable { value in
|
||||||
guard let info = value.arrayValue,
|
guard let info = value.arrayValue,
|
||||||
info.count == 2,
|
info.count == 2,
|
||||||
@ -368,14 +368,18 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
|
|||||||
autocmd BufEnter * call rpcnotify(\(channel), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
autocmd BufEnter * call rpcnotify(\(channel), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
||||||
autocmd DirChanged * call rpcnotify(\( channel), 'autocommand', 'dirchanged', expand('<afile>'))
|
autocmd DirChanged * call rpcnotify(\( channel), 'autocommand', 'dirchanged', expand('<afile>'))
|
||||||
autocmd BufModifiedSet * call rpcnotify(\(channel), 'autocommand', 'bufmodifiedset', str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
autocmd BufModifiedSet * call rpcnotify(\(channel), 'autocommand', 'bufmodifiedset', str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
||||||
""", opts: [:])
|
""", opts: [:], errWhenBlocked: false)
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
.asCompletable()
|
.asCompletable()
|
||||||
.andThen(self.api.subscribe(event: NvimView.rpcEventName))
|
.andThen(self.api.subscribe(event: NvimView.rpcEventName, expectsReturnValue: false))
|
||||||
.andThen(
|
.andThen(
|
||||||
self.sourceFileUrls.reduce(.empty()) { prev, url in
|
self.sourceFileUrls.reduce(.empty()) { prev, url in
|
||||||
prev.andThen(
|
prev.andThen(
|
||||||
self.api.exec2(src: "source \(url.shellEscapedPath)", opts: ["output": true])
|
self.api.exec2(
|
||||||
|
src: "source \(url.shellEscapedPath)",
|
||||||
|
opts: ["output": true],
|
||||||
|
errWhenBlocked: false
|
||||||
|
)
|
||||||
.map { retval in
|
.map { retval in
|
||||||
guard let output = retval["output"]?.stringValue else {
|
guard let output = retval["output"]?.stringValue else {
|
||||||
throw RxNeovimApi.Error
|
throw RxNeovimApi.Error
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,19 @@ public final class RxNeovimApi {
|
|||||||
|
|
||||||
public func stop() -> Completable { self.msgpackRpc.stop() }
|
public func stop() -> Completable { self.msgpackRpc.stop() }
|
||||||
|
|
||||||
|
public func checkBlocked<T>(_ single: Single<T>) -> Single<T> {
|
||||||
|
self
|
||||||
|
.getMode()
|
||||||
|
.flatMap { dict -> Single<T> in
|
||||||
|
guard (dict["blocking"]?.boolValue ?? false) == false else {
|
||||||
|
throw RxNeovimApi.Error.blocked
|
||||||
|
}
|
||||||
|
|
||||||
|
return single
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public func sendRequest(
|
public func sendRequest(
|
||||||
method: String,
|
method: String,
|
||||||
params: [RxNeovimApi.Value]
|
params: [RxNeovimApi.Value]
|
||||||
|
@ -12,11 +12,21 @@ import io
|
|||||||
|
|
||||||
void_func_template = Template('''\
|
void_func_template = Template('''\
|
||||||
public func ${func_name}(${args}
|
public func ${func_name}(${args}
|
||||||
|
expectsReturnValue: Bool = false
|
||||||
) -> Completable {
|
) -> Completable {
|
||||||
|
|
||||||
let params: [RxNeovimApi.Value] = [
|
let params: [RxNeovimApi.Value] = [
|
||||||
${params}
|
${params}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if expectsReturnValue {
|
||||||
|
return self
|
||||||
|
.checkBlocked(
|
||||||
|
self.sendRequest(method: "${nvim_func_name}", params: params)
|
||||||
|
)
|
||||||
|
.asCompletable()
|
||||||
|
}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.sendRequest(method: "${nvim_func_name}", params: params)
|
.sendRequest(method: "${nvim_func_name}", params: params)
|
||||||
.asCompletable()
|
.asCompletable()
|
||||||
@ -26,6 +36,7 @@ void_func_template = Template('''\
|
|||||||
get_mode_func_template = Template('''\
|
get_mode_func_template = Template('''\
|
||||||
public func ${func_name}(${args}
|
public func ${func_name}(${args}
|
||||||
) -> Single<${result_type}> {
|
) -> Single<${result_type}> {
|
||||||
|
|
||||||
let params: [RxNeovimApi.Value] = [
|
let params: [RxNeovimApi.Value] = [
|
||||||
${params}
|
${params}
|
||||||
]
|
]
|
||||||
@ -43,7 +54,9 @@ get_mode_func_template = Template('''\
|
|||||||
|
|
||||||
func_template = Template('''\
|
func_template = Template('''\
|
||||||
public func ${func_name}(${args}
|
public func ${func_name}(${args}
|
||||||
|
errWhenBlocked: Bool = true
|
||||||
) -> Single<${result_type}> {
|
) -> Single<${result_type}> {
|
||||||
|
|
||||||
let params: [RxNeovimApi.Value] = [
|
let params: [RxNeovimApi.Value] = [
|
||||||
${params}
|
${params}
|
||||||
]
|
]
|
||||||
@ -56,6 +69,14 @@ func_template = Template('''\
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errWhenBlocked {
|
||||||
|
return self
|
||||||
|
.checkBlocked(
|
||||||
|
self.sendRequest(method: "${nvim_func_name}", params: params)
|
||||||
|
)
|
||||||
|
.map(transform)
|
||||||
|
}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
.sendRequest(method: "${nvim_func_name}", params: params)
|
.sendRequest(method: "${nvim_func_name}", params: params)
|
||||||
.map(transform)
|
.map(transform)
|
||||||
@ -331,7 +352,6 @@ def parse_args(raw_params):
|
|||||||
params = dict(zip(names, types))
|
params = dict(zip(names, types))
|
||||||
|
|
||||||
result = '\n'.join([n + ': ' + t + ',' for n, t in params.items()])
|
result = '\n'.join([n + ': ' + t + ',' for n, t in params.items()])
|
||||||
result = result[:-1]
|
|
||||||
if not result:
|
if not result:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user