akiyosi / goneovim

A GUI frontend for neovim.
MIT License
2.39k stars 62 forks source link

The nvim process isn't closed when goneovim exit by 'close' button #422

Closed damanis closed 1 year ago

damanis commented 1 year ago

OS: LInux

damanis commented 1 year ago

Seems, need notify nvim process about exit. Also, need to let user save changes (nvim provides confirm qa command).

damanis commented 1 year ago

@akiyosi I tried this patch. It works when file saved, but goneovim window stucks if file has unsaved changes.

diff --git a/editor/editor.go b/editor/editor.go
index 8902918..9a3439e 100644
--- a/editor/editor.go
+++ b/editor/editor.go
@@ -328,6 +328,16 @@ func InitEditor(options Options, args []string) {
    // When an application is closed with the Close button
    e.window.ConnectCloseEvent(func(event *gui.QCloseEvent) {
        e.putLog("The application was closed outside of Neovim's commands, such as the Close button.")
+       for _, ws := range e.workspaces {
+           ftChan := make(chan error)
+           go func() {
+               err = ws.nvim.Command("confirm qa");
+               ftChan <-err;
+           }()
+           select {
+           case <-ftChan:
+           }
+       }
        e.cleanup()
        e.saveSessions()
        if runtime.GOOS == "darwin" {
akiyosi commented 1 year ago

@damanis Thanks for this report! I was inspired by your patch and have created a patch to remedy this issue.

https://github.com/akiyosi/goneovim/commit/675445273170c0a259fa1c706c7448222adcb16d

I tried this patch. It works when file saved, but goneovim window stucks if file has unsaved changes.

Upon investigation of the above problem, the reason for the stacks is that while nvim is waiting for user input ([Y]es or [N]o or [C]ancel), the execution of the command is not completed and goneovim is stopped in the process of select. Here, goneovim needed to send the nvim command and exit the function without waiting for it to be processed and ignore the QCloseEvent event.

damanis commented 1 year ago

@akiyosi Thank for explanation! Interesting subtleties.

akiyosi commented 1 year ago

I have merged the patch and will close it.