Skip to content

Commit fb2efa3

Browse files
committed
refactor: remove use of nvim_err_writeln, update vim.notify usage
1 parent 4258a0a commit fb2efa3

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

lua/flatten/core.lua

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ local M = {}
44
function M.unblock_guest(guest_pipe)
55
local ok, response_sock = require("flatten.guest").sockconnect(guest_pipe)
66
if not ok then
7-
vim.notify("Failed to connect to guest.", vim.log.levels.WARN, {
8-
title = "Flatten",
9-
})
7+
vim.notify(
8+
string.format("Failed to connect to rpc host on '%s'.", guest_pipe),
9+
vim.log.levels.WARN,
10+
{
11+
title = "flatten.nvim",
12+
}
13+
)
1014
return
1115
end
1216
vim.rpcnotify(
@@ -120,6 +124,8 @@ function M.parse_argv(argv)
120124
return pre_cmds, post_cmds
121125
end
122126

127+
---@param opts { argv: string[], response_pipe: string, guest_cwd: string }
128+
---@return boolean
123129
function M.run_commands(opts)
124130
local argv = opts.argv
125131

@@ -328,9 +334,15 @@ function M.edit_files(opts)
328334
end
329335
bufnr = focus.bufnr
330336
else
331-
vim.api.nvim_err_writeln(
332-
"Flatten: 'config.open.focus' expects a function or string, got "
333-
.. type(open)
337+
vim.notify(
338+
string.format(
339+
"'config.open.focus' expects a function or string, got %s",
340+
type(open)
341+
),
342+
vim.log.levels.ERROR,
343+
{
344+
title = "flatten.nvim",
345+
}
334346
)
335347
return false
336348
end

lua/flatten/guest.lua

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@ function M.maybe_block(block)
2626
vim.cmd.qa({ bang = true })
2727
end
2828
waiting = true
29-
vim.wait(math.huge, function()
30-
return waiting == false
31-
or vim.api.nvim_get_chan_info(host) == vim.empty_dict()
32-
end)
33-
vim.cmd.qa({ bang = true })
29+
if
30+
vim.wait(math.huge, function()
31+
return waiting == false
32+
or vim.api.nvim_get_chan_info(host) == vim.empty_dict()
33+
end, nil, true)
34+
then
35+
vim.cmd.qa({ bang = true })
36+
else
37+
vim.notify(
38+
"Waiting interrupted by user",
39+
vim.log.levels.WARN,
40+
{ title = "flatten.nvim" }
41+
)
42+
end
3443
end
3544

3645
function M.send_files(files, stdin)

0 commit comments

Comments
 (0)