Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lua/flatten/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ local M = {}

function M.unblock_guest(guest_pipe)
local response_sock = vim.fn.sockconnect("pipe", guest_pipe, { rpc = true })
vim.rpcnotify(
vim.rpcrequest(
response_sock,
"nvim_exec_lua",
---@diagnostic disable-next-line: param-type-mismatch
"vim.cmd.qa({ bang = true })",
"vim.defer_fn(function() vim.cmd.qa({ bang = true }) end, 25)",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this with just vim.schedule? I'd like to avoid timers here if possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why I've used defer_fn instead of schedule but schedule seems to work as well.

{}
)
vim.fn.chanclose(response_sock)
Expand Down
2 changes: 1 addition & 1 deletion lua/flatten/guest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function M.maybe_block(block)
end
vim.fn.chanclose(host)
while true do
vim.cmd.sleep(1)
vim.cmd.sleep(10)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this should just be changed to vim.wait - I will look into this now. I wrote the original code for this quite a while ago when I was a lot less familiar with Neovim's internals and APIs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a big problem with vim.wait - it is async, meaning guest stays fully responsive which is what we do not want because a user can accidentally mess up guest. sleep on the other hand fully blocks guest neovim instance.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure this is the case - vim.wait is blocking (for Lua), it just may not fully block the event loop - I don't think the guest is responsive while blocked. It definitely isn't for me, main is using vim.wait now and it works for me :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is blocking the function where it is called but it is not blocking the UI.

Try this:

  1. Open terminal: :term
  2. Add something to index
  3. git commit
  4. Return to the terminal buffer in host
  5. i once, you will enter terminal mode in host <- this is expected
  6. i second time, you will enter insert mode in guest <- this should not happen but it does because vim.wait only blocks maybe_block

That's why I believe it is better to use sleep.

end
end

Expand Down