1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-27 14:14:19 +03:00

Merge remote-tracking branch 'origin/pr/1053'

This commit is contained in:
Tae Won Ha 2024-04-26 14:30:33 +02:00
commit 51a4efee34
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
6 changed files with 3775 additions and 1191 deletions

View File

@ -43,7 +43,7 @@ public extension NvimView {
let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars)
: self.vimPlainString(chars)
_ = self.api.input(keys: finalInput).syncValue()
_ = self.api.input(keys: finalInput, errWhenBlocked: false).syncValue()
self.keyDownDone = true
}
@ -60,7 +60,7 @@ public extension NvimView {
// try? self.api.feedkeys(keys: self.vimPlainString(text), mode:"m", escape_ks: false)
// .wait()
_ = self.api.input(keys: self.vimPlainString(text)).syncValue()
_ = self.api.input(keys: self.vimPlainString(text), errWhenBlocked: false).syncValue()
if self.hasMarkedText() { self._unmarkText() }
self.keyDownDone = true
@ -125,7 +125,7 @@ public extension NvimView {
// So we escape as early as possible
if chars == "\0" {
self.api
.input(keys: self.wrapNamedKeys("Nul"))
.input(keys: self.wrapNamedKeys("Nul"), errWhenBlocked: false)
.subscribe(onFailure: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})
@ -138,7 +138,7 @@ public extension NvimView {
// Also mentioned in MacVim's KeyBindings.plist
if flags == .control, chars == "6" {
self.api
.input(keys: "\u{1e}") // AKA ^^
.input(keys: "\u{1e}", errWhenBlocked: false) // AKA ^^
.subscribe(onFailure: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})
@ -149,7 +149,7 @@ public extension NvimView {
if flags == .control, chars == "2" {
// <C-2> should generate \0, escaping as above
self.api
.input(keys: self.wrapNamedKeys("Nul"))
.input(keys: self.wrapNamedKeys("Nul"), errWhenBlocked: false)
.subscribe(onFailure: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})

View File

@ -99,7 +99,7 @@ extension NvimView {
// NvimView.swift
try? self.api.run(inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
.andThen(
self.api.getApiInfo()
self.api.getApiInfo(errWhenBlocked: false)
.flatMapCompletable { value in
guard let info = value.arrayValue,
info.count == 2,
@ -128,7 +128,7 @@ extension NvimView {
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 VimEnter * call rpcrequest(\(channel), 'vimenter')
""", opts: [:])
""", opts: [:], errWhenBlocked: false)
// swiftformat:enable all
.asCompletable()
}

View File

@ -350,7 +350,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
private var _characterspacing = NvimView.defaultCharacterspacing
private func doSetupForVimenterAndSendResponse(forMsgid msgid: UInt32) {
self.api.getApiInfo()
self.api.getApiInfo(errWhenBlocked: false)
.flatMapCompletable { value in
guard let info = value.arrayValue,
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 DirChanged * call rpcnotify(\( channel), 'autocommand', 'dirchanged', expand('<afile>'))
autocmd BufModifiedSet * call rpcnotify(\(channel), 'autocommand', 'bufmodifiedset', str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
""", opts: [:])
""", opts: [:], errWhenBlocked: false)
// swiftformat:enable all
.asCompletable()
.andThen(self.api.subscribe(event: NvimView.rpcEventName))
.andThen(self.api.subscribe(event: NvimView.rpcEventName, expectsReturnValue: false))
.andThen(
self.sourceFileUrls.reduce(.empty()) { prev, url in
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
guard let output = retval["output"]?.stringValue else {
throw RxNeovimApi.Error

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,19 @@ public final class RxNeovimApi {
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(
method: String,
params: [RxNeovimApi.Value]

View File

@ -12,11 +12,21 @@ import io
void_func_template = Template('''\
public func ${func_name}(${args}
expectsReturnValue: Bool = false
) -> Completable {
let params: [RxNeovimApi.Value] = [
${params}
]
if expectsReturnValue {
return self
.checkBlocked(
self.sendRequest(method: "${nvim_func_name}", params: params)
)
.asCompletable()
}
return self
.sendRequest(method: "${nvim_func_name}", params: params)
.asCompletable()
@ -26,6 +36,7 @@ void_func_template = Template('''\
get_mode_func_template = Template('''\
public func ${func_name}(${args}
) -> Single<${result_type}> {
let params: [RxNeovimApi.Value] = [
${params}
]
@ -43,7 +54,9 @@ get_mode_func_template = Template('''\
func_template = Template('''\
public func ${func_name}(${args}
errWhenBlocked: Bool = true
) -> Single<${result_type}> {
let params: [RxNeovimApi.Value] = [
${params}
]
@ -56,6 +69,14 @@ func_template = Template('''\
return result
}
if errWhenBlocked {
return self
.checkBlocked(
self.sendRequest(method: "${nvim_func_name}", params: params)
)
.map(transform)
}
return self
.sendRequest(method: "${nvim_func_name}", params: params)
.map(transform)
@ -331,7 +352,6 @@ def parse_args(raw_params):
params = dict(zip(names, types))
result = '\n'.join([n + ': ' + t + ',' for n, t in params.items()])
result = result[:-1]
if not result:
return ''