From 977e789d8c54b523d4119282f4c910f9886feadb Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Wed, 13 Apr 2022 00:49:18 +0300 Subject: [PATCH] parallelise calls to nvim gRPC api where possible idk if this is actually faster or not, gotta test it out Signed-off-by: Kipras Melnikovas --- nvim-git-rebase-todo/nvim-git-rebase-todo.ts | 58 ++++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/nvim-git-rebase-todo/nvim-git-rebase-todo.ts b/nvim-git-rebase-todo/nvim-git-rebase-todo.ts index e6c458e6..b1107990 100644 --- a/nvim-git-rebase-todo/nvim-git-rebase-todo.ts +++ b/nvim-git-rebase-todo/nvim-git-rebase-todo.ts @@ -163,10 +163,11 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void { width, // height, }: SetWindowRelativeToCursorOpts): Promise => { - const cursor = await vim.window.cursor; - - const relWin = await vim.window; - const col: number = config.closeToLeft || (await relWin.width); + const [relWin, cursor, col] = await Promise.all([ + vim.window, + vim.window.cursor, + config.closeToLeft || vim.window.width, + ]); return { // relative: "cursor", @@ -195,26 +196,35 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void { * instead of taking it in as param */ - const relWin: Window = await vim.getWindow(); - const col: number = config.closeToLeft || (await relWin.width); - - const opts: OpenWindowOptions = config.relativeToCursor - ? { - ...(await getRelativeWindowOptions({ width, height })), - } - : ({ - relative: "win", - win: relWin.id, - // - width, - height, - // - // anchor: "NE", // TODO is this needed? - row: 0 + (config.closeToLeft ? config.rowLowerIfCloseToLeft : 0), - col, - // - style: "minimal", - } as const); + let relWin: Window; + let col: number; + let opts: OpenWindowOptions; + + if (config.relativeToCursor) { + [relWin, col, opts] = await Promise.all([ + vim.window, // + vim.window.width, + getRelativeWindowOptions({ width, height }), + ]); + } else { + [relWin, col] = await Promise.all([ + vim.window, // + vim.window.width, + ]); + opts = { + relative: "win", + win: relWin.id, + // + width, + height, + // + // anchor: "NE", // TODO is this needed? + row: 0 + (config.closeToLeft ? config.rowLowerIfCloseToLeft : 0), + col, + // + style: "minimal", + }; + } const enter = false; const window: number | Window = await vim.openWindow(buffer, enter, opts);