prabirshrestha / vim-lsp

async language server protocol plugin for vim and neovim
MIT License
3.07k stars 303 forks source link

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

Open flwyd opened 8 months ago

flwyd commented 8 months ago

Steps to reproduce:

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 commented 7 months ago

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.

basharh commented 4 months ago

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

ilya-bobyr commented 5 days ago

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.