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

Fix and adapt API generation

- Do not remove the `nvim_` prefix
This commit is contained in:
Tae Won Ha 2024-05-31 13:06:01 +09:00
parent 80fb7e3ba9
commit fd842a2500
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
13 changed files with 330 additions and 328 deletions

View File

@ -34,12 +34,12 @@ public extension NvimView {
}
func isBlocked() -> Single<Bool> {
self.api.getMode().map { dict in dict["blocking"]?.boolValue ?? false }
self.api.nvimGetMode().map { dict in dict["blocking"]?.boolValue ?? false }
}
func hasDirtyBuffers() -> Single<Bool> {
self.api
.execLua(code: """
.nvimExecLua(code: """
return vim.fn.getbufinfo({"bufmodified": v:true})
""", args: [])
.map { result -> Bool in
@ -67,7 +67,7 @@ public extension NvimView {
func currentBuffer() -> Single<NvimView.Buffer> {
self.api
.getCurrentBuf()
.nvimGetCurrentBuf()
.flatMap { [weak self] in
guard let single = self?.neoVimBuffer(for: $0, currentBuffer: $0) else {
throw RxNeovimApi.Error.exception(message: "Could not get buffer")
@ -79,7 +79,7 @@ public extension NvimView {
func allBuffers() -> Single<[NvimView.Buffer]> {
Single
.zip(self.api.getCurrentBuf(), self.api.listBufs()) { (curBuf: $0, bufs: $1) }
.zip(self.api.nvimGetCurrentBuf(), self.api.nvimListBufs()) { (curBuf: $0, bufs: $1) }
.map { [weak self] tuple in
tuple.bufs.compactMap { buf in
self?.neoVimBuffer(for: buf, currentBuffer: tuple.curBuf)
@ -98,9 +98,9 @@ public extension NvimView {
func allTabs() -> Single<[NvimView.Tabpage]> {
Single.zip(
self.api.getCurrentBuf(),
self.api.getCurrentTabpage(),
self.api.listTabpages()
self.api.nvimGetCurrentBuf(),
self.api.nvimGetCurrentTabpage(),
self.api.nvimListTabpages()
) { (curBuf: $0, curTab: $1, tabs: $2) }
.map { [weak self] tuple in
tuple.tabs.compactMap { tab in
@ -113,7 +113,7 @@ public extension NvimView {
func newTab() -> Completable {
self.api
.command(command: "tabe")
.nvimCommand(command: "tabe")
.subscribe(on: self.scheduler)
}
@ -129,7 +129,7 @@ public extension NvimView {
let bufExists = buffers.contains { $0.url == url }
let wins = tabs.map(\.windows).flatMap { $0 }
if let win = bufExists ? wins.first(where: { win in win.buffer.url == url }) : nil {
return self?.api.setCurrentWin(window: RxNeovimApi.Window(win.handle))
return self?.api.nvimSetCurrentWin(window: RxNeovimApi.Window(win.handle))
}
return currentBufferIsTransient ? self?.open(url, cmd: "e") : self?
@ -168,7 +168,7 @@ public extension NvimView {
.map { tabs in tabs.map(\.windows).flatMap { $0 } }
.flatMapCompletable { [weak self] wins -> Completable in
if let win = wins.first(where: { $0.buffer == buffer }) {
guard let completable = self?.api.setCurrentWin(window: RxNeovimApi.Window(win.handle))
guard let completable = self?.api.nvimSetCurrentWin(window: RxNeovimApi.Window(win.handle))
else {
throw RxNeovimApi.Error.exception(message: "Could not set current win")
}
@ -176,7 +176,7 @@ public extension NvimView {
return completable
}
guard let completable = self?.api.command(command: "tab sb \(buffer.handle)") else {
guard let completable = self?.api.nvimCommand(command: "tab sb \(buffer.handle)") else {
throw RxNeovimApi.Error.exception(message: "Could tab sb")
}
return completable
@ -186,44 +186,44 @@ public extension NvimView {
func goTo(line: Int) -> Completable {
self.api
.command(command: "\(line)")
.nvimCommand(command: "\(line)")
.subscribe(on: self.scheduler)
}
/// Closes the current window.
func closeCurrentTab() -> Completable {
self.api
.command(command: "q")
.nvimCommand(command: "q")
.subscribe(on: self.scheduler)
}
func saveCurrentTab() -> Completable {
self.api
.command(command: "w")
.nvimCommand(command: "w")
.subscribe(on: self.scheduler)
}
func saveCurrentTab(url: URL) -> Completable {
self.api
.command(command: "w \(url.shellEscapedPath)")
.nvimCommand(command: "w \(url.shellEscapedPath)")
.subscribe(on: self.scheduler)
}
func closeCurrentTabWithoutSaving() -> Completable {
self.api
.command(command: "q!")
.nvimCommand(command: "q!")
.subscribe(on: self.scheduler)
}
func quitNeoVimWithoutSaving() -> Completable {
self.api
.command(command: "qa!")
.nvimCommand(command: "qa!")
.subscribe(on: self.scheduler)
}
func vimOutput(of command: String) -> Single<String> {
self.api
.exec2(src: command, opts: ["output": true])
.nvimExec2(src: command, opts: ["output": true])
.map {
retval in
guard let output_value = retval["output"] ?? retval["output"],
@ -236,9 +236,9 @@ public extension NvimView {
func cursorGo(to position: Position) -> Completable {
self.api
.getCurrentWin()
.nvimGetCurrentWin()
.flatMapCompletable { [weak self] curWin in
guard let completable = self?.api.winSetCursor(
guard let completable = self?.api.nvimWinSetCursor(
window: curWin,
pos: [position.row, position.column]
) else {
@ -262,7 +262,7 @@ public extension NvimView {
for buf: RxNeovimApi.Buffer,
currentBuffer: RxNeovimApi.Buffer?
) -> Single<NvimView.Buffer> {
self.api.execLua(code: """
self.api.nvimExecLua(code: """
local function map(tbl, f)
local t = {}
for k,v in pairs(tbl) do
@ -316,7 +316,7 @@ public extension NvimView {
private func open(_ url: URL, cmd: String) -> Completable {
self.api
.command(command: "\(cmd) \(url.shellEscapedPath)")
.nvimCommand(command: "\(cmd) \(url.shellEscapedPath)")
.subscribe(on: self.scheduler)
}
@ -326,7 +326,7 @@ public extension NvimView {
currentBuffer: RxNeovimApi.Buffer?
) -> Single<NvimView.Window> {
self.api
.winGetBuf(window: window)
.nvimWinGetBuf(window: window)
.flatMap { [weak self] buf in
guard let single = self?.neoVimBuffer(for: buf, currentBuffer: currentBuffer) else {
throw RxNeovimApi.Error.exception(message: "Could not get buffer")
@ -348,8 +348,8 @@ public extension NvimView {
currentBuffer: RxNeovimApi.Buffer?
) -> Single<NvimView.Tabpage> {
Single.zip(
self.api.tabpageGetWin(tabpage: tabpage),
self.api.tabpageListWins(tabpage: tabpage)
self.api.nvimTabpageGetWin(tabpage: tabpage),
self.api.nvimTabpageListWins(tabpage: tabpage)
) { (curWin: $0, wins: $1) }
.map { [weak self] tuple in
tuple.wins.compactMap { win in

View File

@ -43,7 +43,7 @@ public extension NvimView {
let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars)
: self.vimPlainString(chars)
_ = self.api.input(keys: finalInput, errWhenBlocked: false).syncValue()
_ = self.api.nvimInput(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), errWhenBlocked: false).syncValue()
_ = self.api.nvimInput(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"), errWhenBlocked: false)
.nvimInput(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}", errWhenBlocked: false) // AKA ^^
.nvimInput(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"), errWhenBlocked: false)
.nvimInput(keys: self.wrapNamedKeys("Nul"), errWhenBlocked: false)
.subscribe(onFailure: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})
@ -183,7 +183,7 @@ public extension NvimView {
}
if replacementRange.length > 0 {
let text = String(repeating: "<BS>", count: replacementRange.length)
try? self.api.feedkeys(keys: text, mode: "i", escape_ks: false)
try? self.api.nvimFeedkeys(keys: text, mode: "i", escape_ks: false)
.wait()
}

View File

@ -42,14 +42,14 @@ extension NvimView {
switch self.mode {
case .insert, .replace:
self.api
.input(keys: "<Esc>ui")
.nvimInput(keys: "<Esc>ui")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not undo", cause: error))
})
.disposed(by: self.disposeBag)
case .normal, .visual:
self.api
.input(keys: "u")
.nvimInput(keys: "u")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not undo", cause: error))
})
@ -63,14 +63,14 @@ extension NvimView {
switch self.mode {
case .insert, .replace:
self.api
.input(keys: "<Esc><C-r>i")
.nvimInput(keys: "<Esc><C-r>i")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not redo", cause: error))
})
.disposed(by: self.disposeBag)
case .normal, .visual:
self.api
.input(keys: "<C-r>")
.nvimInput(keys: "<C-r>")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not redo", cause: error))
})
@ -84,7 +84,7 @@ extension NvimView {
switch self.mode {
case .visual, .normal:
self.api
.input(keys: "\"+d")
.nvimInput(keys: "\"+d")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not cut", cause: error))
})
@ -98,7 +98,7 @@ extension NvimView {
switch self.mode {
case .visual, .normal:
self.api
.input(keys: "\"+y")
.nvimInput(keys: "\"+y")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not copy", cause: error))
})
@ -113,7 +113,7 @@ extension NvimView {
// phase == 1 means paste in a single call
self.api
.paste(data: content, crlf: false, phase: -1)
.nvimPaste(data: content, crlf: false, phase: -1)
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not paste \(content)", cause: error))
})
@ -124,7 +124,7 @@ extension NvimView {
switch self.mode {
case .normal, .visual:
self.api
.input(keys: "x")
.nvimInput(keys: "x")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not delete", cause: error))
})
@ -138,14 +138,14 @@ extension NvimView {
switch self.mode {
case .insert, .visual:
self.api
.input(keys: "<Esc>ggVG")
.nvimInput(keys: "<Esc>ggVG")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not select all", cause: error))
})
.disposed(by: self.disposeBag)
default:
self.api
.input(keys: "ggVG")
.nvimInput(keys: "ggVG")
.subscribe(onFailure: { [weak self] error in
self?.eventsSubject.onNext(.apiError(msg: "Could not select all", cause: error))
})

View File

@ -59,8 +59,8 @@ public extension NvimView {
cellPosition: cellPosition
)
self.api
.input(keys: vimInputX).asCompletable()
.andThen(self.api.input(keys: vimInputY).asCompletable())
.nvimInput(keys: vimInputX).asCompletable()
.andThen(self.api.nvimInput(keys: vimInputY).asCompletable())
.subscribe(onError: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})
@ -94,13 +94,13 @@ public extension NvimView {
"# scroll: \(cellPosition.row + vertSign * absDeltaY) \(cellPosition.column + horizSign * absDeltaX)"
)
self.api.winGetCursor(window: RxNeovimApi.Window(0))
self.api.nvimWinGetCursor(window: RxNeovimApi.Window(0))
.flatMapCompletable { cursor in
guard cursor.count == 2 else {
self.log.error("Error decoding \(cursor)")
return Completable.empty()
}
return self.api.winSetCursor(
return self.api.nvimWinSetCursor(
window: RxNeovimApi.Window(0),
pos: [cursor[0] + vertSign * absDeltaY, cursor[1] + horizSign * absDeltaX]
)
@ -169,7 +169,7 @@ public extension NvimView {
}
self.api
.input(keys: result)
.nvimInput(keys: result)
.subscribe(onFailure: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})

View File

@ -56,14 +56,14 @@ extension NvimView {
final func signalRemoteOptionChange(_ option: RemoteOption) {
let command: Completable = switch option {
case let .guifont(fontSpec):
self.api.setOptionValue(
self.api.nvimSetOptionValue(
name: "guifont",
value: .string(fontSpec),
opts: ["scope": .string("global")]
)
case let .guifontWide(fontSpec):
self.api.setOptionValue(
self.api.nvimSetOptionValue(
name: "guifontwide",
value: .string(fontSpec),
opts: ["scope": .string("global")]
@ -80,7 +80,7 @@ extension NvimView {
}
public final func signalError(code: Int, message: String) {
self.api.errWriteln(str: "E\(code): \(message)")
self.api.nvimErrWriteln(str: "E\(code): \(message)")
.subscribe()
.disposed(by: self.disposeBag)
}

View File

@ -59,7 +59,7 @@ extension NvimView {
self.offset.x = floor((size.width - self.cellSize.width * discreteSize.width.cgf) / 2)
self.offset.y = floor((size.height - self.cellSize.height * discreteSize.height.cgf) / 2)
self.api.uiTryResize(width: discreteSize.width, height: discreteSize.height)
self.api.nvimUiTryResize(width: discreteSize.width, height: discreteSize.height)
.subscribe(onError: { [weak self] error in
self?.log.error("Error in \(#function): \(error)")
})
@ -99,7 +99,7 @@ extension NvimView {
// NvimView.swift
try? self.api.run(inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
.andThen(
self.api.getApiInfo(errWhenBlocked: false)
self.api.nvimGetApiInfo(errWhenBlocked: false)
.flatMapCompletable { value in
guard let info = value.arrayValue,
info.count == 2,
@ -122,7 +122,7 @@ extension NvimView {
}
// swiftformat:disable all
return self.api.exec2(src: """
return self.api.nvimExec2(src: """
let g:gui_vimr = 1
autocmd VimLeave * call rpcnotify(\(channel), 'autocommand', 'vimleave')
autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter')
@ -134,7 +134,7 @@ extension NvimView {
}
)
.andThen(
self.api.uiAttach(width: size.width, height: size.height, options: [
self.api.nvimUiAttach(width: size.width, height: size.height, options: [
"ext_linegrid": true,
"ext_multigrid": false,
"ext_tabline": MessagePackValue(self.usesCustomTabBar),

View File

@ -121,7 +121,7 @@ extension NvimView: NSTouchBarDelegate, NSScrubberDataSource, NSScrubberDelegate
let window = tab.currentWindow ?? tab.windows[0]
self.api
.setCurrentWin(window: RxNeovimApi.Window(window.handle))
.nvimSetCurrentWin(window: RxNeovimApi.Window(window.handle))
.subscribe(on: self.scheduler)
.subscribe(onError: { [weak self] error in
self?.eventsSubject

View File

@ -730,7 +730,7 @@ extension NvimView {
}
func focusGained(_ gained: Bool) -> Completable {
self.api.uiSetFocus(gained: gained)
self.api.nvimUiSetFocus(gained: gained)
}
private func quit() -> Completable {

View File

@ -128,7 +128,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
set {
self.api
.setCurrentDir(dir: newValue.path)
.nvimSetCurrentDir(dir: newValue.path)
.subscribe(on: self.scheduler)
.subscribe(onError: { [weak self] error in
self?.eventsSubject
@ -229,13 +229,13 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
let db = self.disposeBag
self.tabBar?.closeHandler = { [weak self] index, _, _ in
self?.api
.command(command: "tabclose \(index + 1)")
.nvimCommand(command: "tabclose \(index + 1)")
.subscribe()
.disposed(by: db)
}
self.tabBar?.selectHandler = { [weak self] _, tabEntry, _ in
self?.api
.setCurrentTabpage(tabpage: tabEntry.tabpage)
.nvimSetCurrentTabpage(tabpage: tabEntry.tabpage)
.subscribe()
.disposed(by: db)
}
@ -243,7 +243,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
// I don't know why, but `tabm ${last_index}` does not always work.
let command = (index == entries.count - 1) ? "tabm" : "tabm \(index)"
self?.api
.command(command: command)
.nvimCommand(command: command)
.subscribe()
.disposed(by: db)
}
@ -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(errWhenBlocked: false)
self.api.nvimGetApiInfo(errWhenBlocked: false)
.flatMapCompletable { value in
guard let info = value.arrayValue,
info.count == 2,
@ -360,7 +360,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
}
// swiftformat:disable all
return self.api.exec2(src: """
return self.api.nvimExec2(src: """
autocmd BufWinEnter * call rpcnotify(\(channel), 'autocommand', 'bufwinenter', str2nr(expand('<abuf>')))
autocmd BufWinLeave * call rpcnotify(\(channel), 'autocommand', 'bufwinleave', str2nr(expand('<abuf>')))
autocmd TabEnter * call rpcnotify(\(channel), 'autocommand', 'tabenter', str2nr(expand('<abuf>')))
@ -371,11 +371,11 @@ 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.api.nvimSubscribe(event: NvimView.rpcEventName, expectsReturnValue: false))
.andThen(
self.sourceFileUrls.reduce(.empty()) { prev, url in
prev.andThen(
self.api.exec2(
self.api.nvimExec2(
src: "source \(url.shellEscapedPath)",
opts: ["output": true],
errWhenBlocked: false
@ -399,7 +399,7 @@ public final class NvimView: NSView, NSUserInterfaceValidations, NSTextInputClie
guard FileManager.default.fileExists(atPath: ginitPath) else { return .empty() }
self.bridgeLogger.debug("Source'ing ginit.vim")
return self.api.command(command: "source \(ginitPath.shellEscapedPath)")
return self.api.nvimCommand(command: "source \(ginitPath.shellEscapedPath)")
}()
)
}

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@ public final class RxNeovimApi {
public func checkBlocked<T>(_ single: Single<T>) -> Single<T> {
self
.getMode()
.nvimGetMode()
.flatMap { dict -> Single<T> in
guard (dict["blocking"]?.boolValue ?? false) == false else {
throw RxNeovimApi.Error.blocked

View File

@ -370,10 +370,12 @@ def parse_params(raw_params):
def parse_function(f):
args = parse_args(f['parameters'])
template = void_func_template if f['return_type'] == 'void' else func_template
template = get_mode_func_template if f['name'] == 'nvim_get_mode' else template
nvim_func_name = f['name']
template = get_mode_func_template if nvim_func_name == 'nvim_get_mode' else template
result = template.substitute(
func_name=snake_to_camel(f['name'][5:]),
nvim_func_name=f['name'],
func_name=snake_to_camel(nvim_func_name),
nvim_func_name=nvim_func_name,
args=args,
params=parse_params(f['parameters']),
result_type=nvim_type_to_swift(f['return_type']),

View File

@ -158,7 +158,7 @@ extension MainWindow {
(
colorName: colorName,
observable: self.neoVimView.api
.getHl(
.nvimGetHl(
ns_id: 0,
opts: ["name": MessagePackValue(colorName)]
)