equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.86k stars 171 forks source link

nvim.exe does not exit after close button press #944

Open fxliang opened 3 years ago

fxliang commented 3 years ago

hi,

if I use command :q to exit, everything works fine.

however if I click close button on caption bar, nvim.exe and other apps work with nvim (node.exe, python, etc.) not exit properly. a group of process leaves there everytime.

system: windows 10 1909(18363.592) 64bit nvim-qt release with nvim 0.5.1

snipaste_20211028_075538

snipaste_20211028_080802

snipaste_20211028_080141 snipaste_20211028_081216

fxliang commented 1 year ago

any update? I check latest version, it seems not solved. adding some code here to tell nvim backend to exit, might be the solution?

https://github.com/equalsraf/neovim-qt/blob/master/src/gui/mainwindow.cpp

void MainWindow::closeEvent(QCloseEvent *ev)
{
    // Do not save window geometry in '--fullscreen' mode. If saved, all
    // subsequent Neovim-Qt sessions would default to fullscreen mode.
    if (!isFullScreen()) {
        saveWindowGeometry();
    }

    if (m_neovim_requested_close) {
        // If this was requested by nvim, shutdown
        emit closing(m_exitStatus);
        ev->accept();
    } else if (m_shell->close()) {
        // otherwise only if the Neovim shell closes too
        emit closing(m_exitStatus);
        ev->accept();
    } else {
        ev->ignore();
    }
}
equalsraf commented 1 year ago

That function should already be calling m_shell->close() which would result in a call to the Shell class

void Shell::closeEvent(QCloseEvent *ev)
{
    if (m_attached &&
        m_nvim->connectionType() == NeovimConnector::SpawnedConnection) {
        // If attached to a spawned Neovim process, ignore the event
        // and try to close Neovim as :qa
        ev->ignore();
        bailoutIfinputBlocking();
        m_nvim->api0()->vim_command("confirm qa");
    } else {
        QWidget::closeEvent(ev);
    }
}

The event itself is ignored there and confirm qa is used to close neovim. Can you check if this also happens when using :confirm qa manually?

fxliang commented 1 year ago

manually:confirm qa is ok, so does manully using :q

but by click the close button, no. only nvim-qt.exe exit, nvim.exe with sub processes(seems for coc) left there alive.

image

equalsraf commented 1 year ago

I've tried to reproduce this earlier, but no luck so far. In my case I was running python, but all processes terminated when I closed.

It might be worth trying to reproduce without loading any configuration just to be sure (nvim-qt -- -u NOCFG) it is not caused by some plugin/setting.

Maybe we can try to reconnect to the running neovim to see what is happening inside

  1. start nvim-qt normally
  2. inside neovim start listening on a new pip with :call serverstart('\\.\pipe\nvim-qt-944')
  3. do what you usually to make this happen, and press the close button
  4. connect a new nvim-qt to the running nvim nvim-qt --server \\.\pipe\nvim-qt-944
  5. hopefully something will be there (like errors in :messages) but i doubt it
fxliang commented 1 year ago

no error msgs shown...

I try start nvim-qt from powershell( windows terminal), it close normally, no processes left. I make a lnk to nvim-qt -- -u NOCFG, no plugins, close normally, nothing left. any time I start nvim-qt not in console, it would left processes there. don't know why.

equalsraf commented 1 year ago

Maybe some plugin is preventing it from shutting down properly. It is strange that the window is closing though. That would mean this function is being called but nvim does not actually close:

https://github.com/equalsraf/neovim-qt/blob/master/src/gui/runtime/plugin/nvim_gui_shim.vim#L32

Can you share the autogroups that are setup for the leave events?

fxliang commented 1 year ago

image image

equalsraf commented 1 year ago

So coc_nvim is the only one there

Tricky to track past that point.

Just to confirm and narrow it down, can you try disabling the coc.nvim plugin and see if the problem still happens?

fxliang commented 1 year ago

disable coc, close the window with mouse, then nvim.exe,conhosts.exe, python.exe left back.

equalsraf commented 1 year ago

Ok I've come across something that might be related to this one.

See https://github.com/equalsraf/neovim-qt/pull/1076 for a possible fix. Although we might become too aggressive in killing the processes.

fxliang commented 1 year ago

Ok I've come across something that might be related to this one.

See #1076 for a possible fix. Although we might become too aggressive in killing the processes.

pity thing is that windows build not ok...

equalsraf commented 1 year ago

The tests are causing our windows builds to fail :S, here is a working one

https://ci.appveyor.com/project/equalsraf/neovim-qt/builds/47679296/job/7rc7nmxjxw5rb8ex/artifacts

fxliang commented 1 year ago

I've checked that output, it works. Thanks a lot!~