1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-09-11 17:15:34 +03:00

Do setup in blocking vimenter

This commit is contained in:
Tae Won Ha 2023-12-17 11:20:35 +01:00
parent 2a6255b807
commit 02d3a2c445
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 38 additions and 52 deletions

View File

@ -140,22 +140,6 @@ extension NvimView {
"rgb": true,
])
)
.andThen(
self.sourceFileUrls.reduce(.empty()) { prev, url in
prev.andThen(
self.api.exec2(src: "source \(url.shellEscapedPath)", opts: ["output": true])
.map { retval in
guard let output = retval["output"]?.stringValue else {
throw RxNeovimApi.Error
.exception(message: "Could not convert values to output.")
}
return output
}
.asCompletable()
)
}
)
.andThen(self.api.subscribe(event: NvimView.rpcEventName))
.wait()
}

View File

@ -163,40 +163,7 @@ extension NvimView {
self.bridgeLogger.debug("\(event): \(array)")
if event == .vimenter {
Completable
.empty()
.observe(on: SerialDispatchQueueScheduler(qos: .userInitiated))
.andThen(
Completable.create { completable in
self.rpcEventSubscriptionCondition.wait(for: 5)
self.bridgeLogger.debug("RPC events subscription done.")
completable(.completed)
return Disposables.create()
}
)
.andThen(
{
let ginitPath = URL(fileURLWithPath: NSHomeDirectory())
.appendingPathComponent(".config/nvim/ginit.vim").path
let loadGinit = FileManager.default.fileExists(atPath: ginitPath)
if loadGinit {
self.bridgeLogger.debug("Source'ing ginit.vim")
return self.api.command(command: "source \(ginitPath.shellEscapedPath)")
} else {
return .empty()
}
}()
)
// .andThen(self.bridge.notifyReadinessForRpcEvents())
.subscribe(onCompleted: { [weak self] in
self?.log.debug("Notified the NvimServer to fire GUIEnter")
})
.disposed(by: self.disposeBag)
return
}
// vimenter is handled in NvimView.swift
if event == .exitpre {
self.stop()

View File

@ -187,7 +187,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
// This is the only request sent from Neovim to the UI, afaics.
guard method == "vimenter" else { break }
self?.log.debug("Processing blocking vimenter request")
self?.setupAutocmdsAndSendResponse(forMsgid: msgid)
self?.doSetupForVimenterAndSendResponse(forMsgid: msgid)
case let .notification(method, params):
self?.log.trace("NOTIFICATION: \(method): \(params)")
@ -356,7 +356,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
private var _linespacing = NvimView.defaultLinespacing
private var _characterspacing = NvimView.defaultCharacterspacing
private func setupAutocmdsAndSendResponse(forMsgid msgid: UInt32) {
private func doSetupForVimenterAndSendResponse(forMsgid msgid: UInt32) {
self.api.getApiInfo(errWhenBlocked: false)
.flatMapCompletable { value in
guard let info = value.arrayValue,
@ -378,9 +378,44 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
""", opts: [:], errWhenBlocked: false)
// swiftformat:enable all
.asCompletable()
.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],
errWhenBlocked: false
)
.map { retval in
guard let output = retval["output"]?.stringValue else {
throw RxNeovimApi.Error
.exception(message: "Could not convert values to output.")
}
return output
}
.asCompletable()
)
}
)
.andThen(
self.api.sendResponse(msgid: msgid, error: .nil, result: .nil)
)
.andThen(
{
let ginitPath = URL(fileURLWithPath: NSHomeDirectory())
.appendingPathComponent(".config/nvim/ginit.vim").path
if FileManager.default.fileExists(atPath: ginitPath) {
self.bridgeLogger.debug("Source'ing ginit.vim")
return self.api.command(
command: "source \(ginitPath.shellEscapedPath)",
expectsReturnValue: false
)
} else {
return .empty()
}
}()
)
}
.subscribe().disposed(by: self.disposeBag)
}