Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics hover and echo status message hidden by "--No lines in buffer--" #1510

Open
flwyd opened this issue Nov 10, 2023 · 3 comments
Open

Comments

@flwyd
Copy link
Contributor

flwyd commented Nov 10, 2023

Steps to reproduce:

  • Make sure a Python LSP is installed.
  • echo "foo()\nbar()" > /tmp/foo.py
  • vim -u /tmp/minimal.vim /tmp/foo.py
  • When vim opens, move the cursor and see an error like undefined name 'foo' in a popup window and in the status message. Both the window and the status disappear after a few seconds (maybe 5 seconds after moving the cursor?) and the status message becomes --No lines in buffer--.
  • Expected behavior: diagnostics status message and the floating window stay visible until moving the cursor.

Curiously, if g:lsp_diagnostics_float_delay is 500 instead of 2000 or 1000, the "No lines in buffer" message doesn't show up and the diagnostic status message stays in place, though the hover window still disappears after a few seconds. (Is the floating window supposed to disappear? I'd really like it to stay visible until I move the cursor.) 500 seems to be the magic value; anything larger results in "No lines in buffer" messages overwriting the status line while anything smaller doesn't.

Contents of /tmp/minimal.vim, assumes vim-plug is already installed:

set nocompatible

call plug#begin('~/.vim/plugged')
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
call plug#end()

" Configuration for vim-lsp
let g:lsp_signs_enabled = 1
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_diagnostics_float_cursor = 1
let g:lsp_diagnostics_float_delay = 1000
let g:lsp_diagnostics_virtual_text_enabled = 0
let g:lsp_float_max_width = 0

This happens on the system vim for macOS 12.7 (9.0 with patches 1-1544), MacVim 9.0.1897, and a recent gvim on Debian Linux (9.0, don't have the patch list handy). It's not limited to any particular LSP; I've seen it with the Python and Julia LSPs from vim-lsp-settings as well as a company-internal LSP at work.

@4imothy
Copy link

4imothy commented Dec 15, 2023

It seems to be something with when a swap file is written. When I set

set updatetime=0

The float doesn't disappear until I write the file to disk. I think when I write the file to disk that is when the swap file is written as well.

I tried writing to disk with the default update time and the floating window stayed active, apart from a flicker. So I think it is something with writing a swap file and not the buffer's file.

4imothy added a commit to 4imothy/dotfiles that referenced this issue Dec 15, 2023
@basharh
Copy link

basharh commented Mar 15, 2024

I was facing the same issue. Seems like this may be related to the CursorHold autocommand which fires after updatetime milliseconds. From the vim-lsp code this seems to be by design:

\ lsp#callbag#fromEvent(['CursorMoved', 'CursorHold']),

:help updatetime

'updatetime' 'ut'	number	(default 4000)
			global
	If this many milliseconds nothing is typed the swap file will be
	written to disk (see |crash-recovery|).  Also used for the
	|CursorHold| autocommand event.

Removing CursorHold from the line above did not solve the issue but there are other calls to CursorHold that might be removing floats

@ilya-bobyr
Copy link
Contributor

Somehow, my Vim seems to be also generating a CursorMove event along with the CursorHold event.
So just the removal of the CursorHold from the list was not enough.

While trying to fix this exact issue I've changed a few things in this area, ultimately adding a configuration option to disable the "hide on CursorHold" behavior:

let g:lsp_diagnostics_float_hide_on_cursor_hold = 0

The first change in the series is posted for review.
If you want to get this functionality before the review process is done, you can apply this to your .vimrc:

- Plug 'prabirshrestha/vim-lsp'
+ Plug 'ilya-bobyr/vim-lsp'
+ let g:lsp_diagnostics_float_hide_on_cursor_hold = 0

Or, maybe, be even more precise with the exact change you want:

- Plug 'prabirshrestha/vim-lsp'
+ Plug 'ilya-bobyr/vim-lsp', { 'commit': '61e72298180f7937cf5c141e6482ab9cbc64f3b9' }
+ let g:lsp_diagnostics_float_hide_on_cursor_hold = 0

It would also be nice to get someone else to try my changes.
The event processing logic is somewhat tricky.
While it does seem to work for me, there is a chance I broke an existing behavior others rely on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants