akiyosi / goneovim

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

goneovim window does not close with latest neovim releases #434

Closed damanis closed 3 months ago

damanis commented 1 year ago

Steps to reproduce:

Expected: file saved, then goneovim closed Problem: goneovim window isn't closed. The neovim process (ps ax) does not exist, but goneovim process still exists.

It is not goneovim specific, nvui also has it, but not nvim-qt. Seems, something changed in nvim API.

akiyosi commented 1 year ago

Hi, Thanks for this issue report. I cannot reproduce the problem on my machine using the steps you provided. I think the problem may be related to a specific plugin.

Is the problem reproducible with the following steps?

damanis commented 1 year ago

@akiyosi You right, it works without plugins. Strange that same plugins used with neovim-qt without any problem. I will check my plugins. P.S. Will you add binaries for Ubuntu 20.04 (older libc)?

akiyosi commented 1 year ago

@damanis Thanks, it would be useful to know which plugins are affecting the problem.

P.S. Will you add binaries for Ubuntu 20.04 (older libc)?

Would this one work?

https://github.com/akiyosi/goneovim/actions/runs/3992430747

damanis commented 1 year ago

@akiyosi I found that problem is not in plugin, but in set clipboard command vim.o.clipboard = [[unnamed]] If comment out it, the problem is not reproduced (but without it PRIMARY selection does not work). Since neovim-qt works properly with clipboard command, it sound like problem in goneovim.

Would this one work? https://github.com/akiyosi/goneovim/actions/runs/3992430747

Yes, this image works.

akiyosi commented 1 year ago

@damanis Thanks for info!

In other words, am I correct in understanding that the problem is reproduced in your environment by the following steps?

  1. Run goneovim with the following
    /path/to/goneovim -u NONE --cmd 'set clipboard=unnamed' /path/to/file
  2. make change, then :wq
damanis commented 1 year ago

@akiyosi Yes, these steps cause the problem.

akiyosi commented 1 year ago

@damanis I have tried to reproduce the problem on my MacOS, archlinux and pop!os machines, but have not been able to reproduce it at this time.

I am thinking that perhaps it has something to do with the clipboard provider. What is the neovim clipboard provider on your system? Reading :h provider-clipboard, it seems that on Linux, there are wl-copy, wl-paste, xclip, etc.

damanis commented 1 year ago

@akiyosi Since commit b042f6d90 neovim prefer xsel. I have it installed.

:checkhealth 
...
Clipboard (optional) ~
- OK Clipboard tool found: xsel
...

I also test with xclip - same behavior.

Seems, any operation with clipboard cause the problem, not change then read only. The goneovim just wait until xsel exists.

damanis commented 1 year ago

@akiyosi I see /usr/bin/xsel --nodetach -i -p in ps ax output when goneovim exits. This command tries copy selection to primary buffer, but, seems, the selection is empty, so goneovim can't exit, because of it waits xsel finishes. If double click (i.e., select something) on any word, for example, in a terminal, goneovim immediately exits.

damanis commented 1 year ago

@akiyosi May be this will help. The workaround clears primary selection buffer before exit. It is default behavior in vim (as I know, it according freedesktop specification), but changed in neovim (nvim-qt successfully saves primary selection on exit).

if vim.g.goneovim then
  -- Workaround: clear primary before exit
  vim.api.nvim_exec([[
    :autocmd VimLeavePre * call setreg('*', [])
  ]], false)
end
akiyosi commented 1 year ago

@damanis Thanks for the info. What are your settings.toml settings?

akiyosi commented 1 year ago

@damanis goneovim adds the following settings if Clipboard = true and the default value is true

https://github.com/akiyosi/goneovim/blob/d91125000f3aa70b1d34a08a8c8a963b05b5d813/editor/workspace.go#L766

If this clipboard setting is enabled, Goneovim will copy the yanked text to the clipboard using https://github.com/atotto/clipboard; on Linux, this copying seems to be done using xsel.

Perhaps you can work around this problem by adding the following to settings.toml It is arguable whether the default value should be true or false.

[Editor]
# Copy yanked text to clipboard
Clipboard = false
damanis commented 1 year ago

@akiyosi

I have clipboard = false in ~/.config/goneovim/settings.toml - it doesn't help.

I compared goneovim and nvim-qt behavior on exit by execsnoop-bpfcc (it show execv calls): goneovim calls /usr/bin/xsel --nodetach -i -p at exit, while nvim-qt doesn't, so it doesn't stuck. nvim-qt doesn't touch primary selection, so previously copied content exists in primary selection after nvim-qt exit.

damanis commented 1 year ago

@akiyosi

As I understand, clipboard module copy primary selection to clipboard. This is another action, not what xsel --nodetach -i -p does: the xsel call copies nvim's * register to primary selection. I think the problem causes, because of nvim process already exited, so * register isn't accessible. The proper behavior, seems, is do not call xsel at exit like nvim-qt does.

akiyosi commented 1 year ago

@damanis Can you post the file contents of your settings.toml?

damanis commented 1 year ago
[Editor]
WindowGeometryBasedOnFontmetrics = true
IgnoreFirstMouseClickWhenAppInactivated = false
Width = 900
Height = 780
LineToScroll = 3
FontFamily = "GoMono Nerd Font Mono"
FontSize = 11
ExtPopupmenu = true
CachedDrawing = true
DisableLigatures = false
Clipboard = false
[Cursor]
SmoothMove = false
[Palette]
[Message]
[Statusline]
Visible = false
[Tabline]
Visible = false
[Popupmenu]
[ScrollBar]
Visible = false
[MiniMap]
Disable = true
[Markdown]
Disable = true
[SideBar]
Visible = false
[FileExplore]
[Workspace]
RestoreSession = false
akiyosi commented 1 year ago

@damanis Thank you. I have identified the direct cause code. I am looking into ways to resolve the issue.

akiyosi commented 1 year ago

Ummm, It seems to be the cause is that the following autocmd. But I have no idea why this autocmd causes such problems...

https://github.com/akiyosi/goneovim/blob/eb1ed9b5ad0e581202bfecf88616a33672ef93e8/editor/workspace.go#L753

I believe you can confirm that the problem does not occur by executing the following command to override the above autocmd after starting goneovim.

:aug Goneovim | au! | aug END
damanis commented 1 year ago

After start goneovim, I entered :aug Goneovim | au! | aug END, then make changes and :wq - problem reproduced.

akiyosi commented 1 year ago

Really? The problem does not reproduce in my Linux environment. I don't understand it even more. I will continue to investigate.

damanis commented 1 year ago

Tested again - reproduced. Goneovim waits until xsel exits as written above. Workaround with clearing * register works.

akiyosi commented 1 year ago

Could you reproduce the problem with the following binaries?

https://github.com/akiyosi/goneovim/actions/runs/4134917312

damanis commented 1 year ago

Yes, reproduced, also after aug command you provided.

akiyosi commented 1 year ago

@damanis Thanks for confirming. Hmmm, so the problem I was able to reproduce in my environment and the problem in yours is the same problem, but the cause is slightly different.

If you exec both of the following commands in your environment, do you reproduce the problem? This will disable all autocmd's that Goneovim needs, so Goneovim may not work properly, but it will isolate the problem.

:aug Goneovim | au! | aug END
:aug GoneovimCore | au! | aug END
damanis commented 1 year ago

@akiyosi I tested on Ubuntu 22: after goneovim started, I entered two commands your provided - problem reproduced. It possible, that the problem not in goneovim hooks, but in QT code: may be, it need to configure some QT option. I tried find something in neovim-qt code (it works with new nvim releases), but didn't find any yet.

akiyosi commented 1 year ago

@damanis The contents of the commit on the neovim side that triggered this problem may tell us something. Do you know the hash value of the commit?

damanis commented 1 year ago

@akiyosi I'm not sure what exactly commit. I thought it is b042f6d9022, but it too old, after it was no problem. I see problem only in GUI uses QT (excluding neovim-qt), all other neovim GUI works properly.

I run goneovim with --debug. After :wq last two line in log should be:

Received GUI event from neovim
The application was quitted with the exit of Neovim.

If problem occurs, second line added only after I select some word by mouse.

damanis commented 1 year ago

@akiyosi I found that problem xsel process ran by jobstart command from runtime/autoload/provider/clipboard.vim (from neovim package):

let jobid = jobstart(selection.argv, selection)
akiyosi commented 1 year ago

@damanis Thanks for this info. I noticed that a change directly related to clipboard is trivial on the commit history in neovim repo. The changes in clipboard.vim seems to be included in this kind of changes. I will make time to investigate with bisect.

b042f6d 2022-11-07 11:46 +0800  wzy                     fix(clipboard): prefer xsel #20918
ef1d291 2022-11-09 16:21 -0700  Gregory Anders      fix(clipboard): update version regex pattern (#21012)
fdeb20d 2022-11-18 15:39 +0000  XDream8             feat(clipboard): added wayclip support (#21091)
5529b07 2023-01-04 07:17 +0800  zeertzjq                fix(clipboard): show provider warning when not during batch changes #21451
akiyosi commented 1 year ago

@damanis Here is a follow-up report on the survey results. I have identified the neovim commit where this problem began to occur as https://github.com/neovim/neovim/commit/1d16bba4d8b8b648d2dabd610924bcf3051a0f29. I have also identified the code for the problem on the Goneovim side.

I am currently working on a fix.

damanis commented 1 year ago

@akiyosi Great news! How did you find it? I also detect that same problem with + buffer (system clipboard). Seems, fix will solve all, the difference only in xsel parameters: xsel --nodetach -i -b instead of xsel --nodetach -i -p.

akiyosi commented 1 year ago

related: https://github.com/neovim/go-client/issues/153

akiyosi commented 1 year ago

@damanis This problem has not yet been fundamentally resolved.

On the other hand, with the most recent fix, goneovim has begun to provide its own clipboard provider(7b7aeb4db2) This makes it possible to work around this problem by setting Clipboard=true in settings.toml.

damanis commented 1 year ago

@akiyosi Yes, I tested it. Note, that goneovim own clipboard provider does not provide all required API now, so some extensions, such as yanky, cannot work. Currently, I prefer workaround with clearing * and + buffers on exit.

akiyosi commented 8 months ago

related: https://github.com/neovim/neovim/issues/26743

damanis commented 8 months ago

related: neovim/neovim#26743

Yes, cross-reference :). It was opened by neovide author after I wrote him with references to your exploring.

damanis commented 3 months ago

@fredizzimo reported that the issue fixed in neovim. Last neovide, 0.13.0 works properly with clipboard.

damanis commented 3 months ago

I tested with neovim 10 release — the problem is not reproduced. Seems, the go-client issue also may be closed.

akiyosi commented 3 months ago

@damanis Thank you! This issue is now closed.