Skip to content

Commit 37b547a

Browse files
authored
v0.1.1 (Builtin server)
* refac(rpc): Use `v.servername` instead of creating pipe * refac: Remove host.lua as it's no longer needed
1 parent 37f9381 commit 37b547a

File tree

4 files changed

+16
-33
lines changed

4 files changed

+16
-33
lines changed

lua/flatten/core.lua

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
local M = {}
22

3-
M.response_sock = nil
4-
5-
local function unblock_client(pipe, othercmds)
6-
M.response_sock = vim.fn.sockconnect("pipe", pipe, { rpc = true })
7-
vim.fn.rpcnotify(M.response_sock, "nvim_exec_lua", "vim.cmd('qa!')", {})
8-
vim.fn.chanclose(M.response_sock)
9-
M.response_sock = nil
3+
local function unblock_guest(guest_pipe, othercmds)
4+
local response_sock = vim.fn.sockconnect("pipe", guest_pipe, { rpc = true })
5+
vim.fn.rpcnotify(response_sock, "nvim_exec_lua", "vim.cmd('qa!')", {})
6+
vim.fn.chanclose(response_sock)
107

118
for _, cmd in ipairs(othercmds) do
129
vim.api.nvim_del_autocmd(cmd)
@@ -22,23 +19,23 @@ local function notify_when_done(pipe, bufnr, callback, ft)
2219
buffer = bufnr,
2320
once = true,
2421
callback = function()
25-
unblock_client(pipe, { bufunload, bufdelete })
22+
unblock_guest(pipe, { bufunload, bufdelete })
2623
callback(ft)
2724
end
2825
})
2926
bufunload = vim.api.nvim_create_autocmd("BufUnload", {
3027
buffer = bufnr,
3128
once = true,
3229
callback = function()
33-
unblock_client(pipe, { quitpre, bufdelete })
30+
unblock_guest(pipe, { quitpre, bufdelete })
3431
callback(ft)
3532
end
3633
})
3734
bufdelete = vim.api.nvim_create_autocmd("BufDelete", {
3835
buffer = bufnr,
3936
once = true,
4037
callback = function()
41-
unblock_client(pipe, { quitpre, bufunload })
38+
unblock_guest(pipe, { quitpre, bufunload })
4239
callback(ft)
4340
end
4441
})

lua/flatten/guest.lua

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
local M = {}
22

3-
M.init = function()
3+
M.init = function(host_pipe)
44
local args = vim.call("argv")
55

6-
local sock = vim.fn.sockconnect("pipe", require('flatten').pipe_path, { rpc = true })
7-
local response_pipe = vim.call("serverstart")
6+
local host = vim.fn.sockconnect("pipe", host_pipe, { rpc = true })
87

98
local call =
109
"return require('flatten.core').edit_files("
1110
.. vim.inspect(args) .. ','
12-
.. vim.inspect(response_pipe) .. ','
11+
.. "'" .. vim.v.servername .. "',"
1312
.. "'" .. vim.fn.getcwd() .. "'" ..
1413
")"
1514

1615
if #args < 1 then return end
1716

18-
local block = vim.fn.rpcrequest(sock, "nvim_exec_lua", call, {})
17+
local block = vim.fn.rpcrequest(host, "nvim_exec_lua", call, {})
1918
if not block then
2019
vim.cmd("qa!")
2120
end
22-
vim.fn.chanclose(sock)
23-
while block do
21+
vim.fn.chanclose(host)
22+
while true do
2423
vim.cmd("sleep 1")
2524
end
2625
end

lua/flatten/host.lua

-8
This file was deleted.

lua/flatten/init.lua

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ M.config = {
1414
}
1515
}
1616

17-
M.pipe_var = "NVIM_FLATTEN_PIPE_PATH"
18-
M.pipe_path = nil
19-
2017
local function flatten_init()
21-
M.pipe_path = os.getenv(M.pipe_var)
22-
if M.pipe_path ~= nil then
23-
require('flatten.guest').init()
24-
else
25-
require('flatten.host').init()
18+
local pipe_path = os.getenv("NVIM")
19+
if pipe_path ~= nil then
20+
require('flatten.guest').init(pipe_path)
2621
end
2722
end
2823

0 commit comments

Comments
 (0)