Skip to content

Commit

Permalink
v0.1.1 (Builtin server)
Browse files Browse the repository at this point in the history
* refac(rpc): Use `v.servername` instead of creating pipe

* refac: Remove host.lua as it's no longer needed
  • Loading branch information
willothy authored Mar 11, 2023
1 parent 37f9381 commit 37b547a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 33 deletions.
17 changes: 7 additions & 10 deletions lua/flatten/core.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -22,23 +19,23 @@ 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
})
bufunload = vim.api.nvim_create_autocmd("BufUnload", {
buffer = bufnr,
once = true,
callback = function()
unblock_client(pipe, { quitpre, bufdelete })
unblock_guest(pipe, { quitpre, bufdelete })
callback(ft)
end
})
bufdelete = vim.api.nvim_create_autocmd("BufDelete", {
buffer = bufnr,
once = true,
callback = function()
unblock_client(pipe, { quitpre, bufunload })
unblock_guest(pipe, { quitpre, bufunload })
callback(ft)
end
})
Expand Down
13 changes: 6 additions & 7 deletions lua/flatten/guest.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 0 additions & 8 deletions lua/flatten/host.lua

This file was deleted.

11 changes: 3 additions & 8 deletions lua/flatten/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 37b547a

Please sign in to comment.