vim-lsp icon indicating copy to clipboard operation
vim-lsp copied to clipboard

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

Open flwyd opened this issue 1 year ago • 3 comments

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.

flwyd avatar Nov 10 '23 07:11 flwyd

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 avatar Dec 15 '23 22:12 4imothy

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: https://github.com/prabirshrestha/vim-lsp/blob/f7ccf006df1aefd327c0e2c55cc8632a2db577c1/autoload/lsp/internal/diagnostics/float.vim#L20

: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

basharh avatar Mar 15 '24 07:03 basharh

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.

ilya-bobyr avatar Jul 23 '24 06:07 ilya-bobyr