diff --git a/lua/flatten/core.lua b/lua/flatten/core.lua index c73ffc2..0ae577d 100644 --- a/lua/flatten/core.lua +++ b/lua/flatten/core.lua @@ -1,12 +1,9 @@ local M = {} -M.response_sock = nil - -local function unblock_client(pipe, othercmds) - M.response_sock = vim.fn.sockconnect("pipe", pipe, { rpc = true }) - vim.fn.rpcnotify(M.response_sock, "nvim_exec_lua", "vim.cmd('qa!')", {}) - vim.fn.chanclose(M.response_sock) - M.response_sock = nil +local function unblock_guest(guest_pipe, othercmds) + local response_sock = vim.fn.sockconnect("pipe", guest_pipe, { rpc = true }) + vim.fn.rpcnotify(response_sock, "nvim_exec_lua", "vim.cmd('qa!')", {}) + vim.fn.chanclose(response_sock) for _, cmd in ipairs(othercmds) do vim.api.nvim_del_autocmd(cmd) @@ -22,7 +19,7 @@ local function notify_when_done(pipe, bufnr, callback, ft) buffer = bufnr, once = true, callback = function() - unblock_client(pipe, { bufunload, bufdelete }) + unblock_guest(pipe, { bufunload, bufdelete }) callback(ft) end }) @@ -30,7 +27,7 @@ local function notify_when_done(pipe, bufnr, callback, ft) buffer = bufnr, once = true, callback = function() - unblock_client(pipe, { quitpre, bufdelete }) + unblock_guest(pipe, { quitpre, bufdelete }) callback(ft) end }) @@ -38,7 +35,7 @@ local function notify_when_done(pipe, bufnr, callback, ft) buffer = bufnr, once = true, callback = function() - unblock_client(pipe, { quitpre, bufunload }) + unblock_guest(pipe, { quitpre, bufunload }) callback(ft) end }) diff --git a/lua/flatten/guest.lua b/lua/flatten/guest.lua index d527014..7f98a43 100644 --- a/lua/flatten/guest.lua +++ b/lua/flatten/guest.lua @@ -1,26 +1,25 @@ local M = {} -M.init = function() +M.init = function(host_pipe) local args = vim.call("argv") - local sock = vim.fn.sockconnect("pipe", require('flatten').pipe_path, { rpc = true }) - local response_pipe = vim.call("serverstart") + local host = vim.fn.sockconnect("pipe", host_pipe, { rpc = true }) local call = "return require('flatten.core').edit_files(" .. vim.inspect(args) .. ',' - .. vim.inspect(response_pipe) .. ',' + .. "'" .. vim.v.servername .. "'," .. "'" .. vim.fn.getcwd() .. "'" .. ")" if #args < 1 then return end - local block = vim.fn.rpcrequest(sock, "nvim_exec_lua", call, {}) + local block = vim.fn.rpcrequest(host, "nvim_exec_lua", call, {}) if not block then vim.cmd("qa!") end - vim.fn.chanclose(sock) - while block do + vim.fn.chanclose(host) + while true do vim.cmd("sleep 1") end end diff --git a/lua/flatten/host.lua b/lua/flatten/host.lua deleted file mode 100644 index 4372308..0000000 --- a/lua/flatten/host.lua +++ /dev/null @@ -1,8 +0,0 @@ -local M = {} - -M.init = function() - local server_pipe = vim.call("serverstart") - vim.call("setenv", require("flatten").pipe_var, server_pipe) -end - -return M diff --git a/lua/flatten/init.lua b/lua/flatten/init.lua index df94ee9..ff4b3de 100644 --- a/lua/flatten/init.lua +++ b/lua/flatten/init.lua @@ -14,15 +14,10 @@ M.config = { } } -M.pipe_var = "NVIM_FLATTEN_PIPE_PATH" -M.pipe_path = nil - local function flatten_init() - M.pipe_path = os.getenv(M.pipe_var) - if M.pipe_path ~= nil then - require('flatten.guest').init() - else - require('flatten.host').init() + local pipe_path = os.getenv("NVIM") + if pipe_path ~= nil then + require('flatten.guest').init(pipe_path) end end