From d595f4133e68cdee0ada821def6086d86a1bf2bf Mon Sep 17 00:00:00 2001 From: Boyang Du Date: Wed, 24 Apr 2024 16:42:52 +0100 Subject: [PATCH] make float auto close configurable --- autoload/lsp/internal/diagnostics/float.vim | 8 ++++++-- doc/vim-lsp.txt | 14 ++++++++++++++ plugin/lsp.vim | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/autoload/lsp/internal/diagnostics/float.vim b/autoload/lsp/internal/diagnostics/float.vim index f7f40a158..8870a683e 100644 --- a/autoload/lsp/internal/diagnostics/float.vim +++ b/autoload/lsp/internal/diagnostics/float.vim @@ -17,7 +17,12 @@ function! lsp#internal#diagnostics#float#_enable() abort let s:Dispose = lsp#callbag#pipe( \ lsp#callbag#merge( - \ lsp#callbag#fromEvent(['CursorMoved', 'CursorHold']), + \ lsp#callbag#fromEvent(['CursorMoved', ]), + \ lsp#callbag#pipe( + \ lsp#callbag#fromEvent(['CursorHold', ]), + \ lsp#callbag#filter({_->g:lsp_diagnostics_float_close_on_hold}), + \ lsp#callbag#tap({_->s:hide_float()}), + \ ), \ lsp#callbag#pipe( \ lsp#callbag#fromEvent(['InsertEnter']), \ lsp#callbag#filter({_->!g:lsp_diagnostics_float_insert_mode_enabled}), @@ -25,7 +30,6 @@ function! lsp#internal#diagnostics#float#_enable() abort \ ) \ ), \ lsp#callbag#filter({_->g:lsp_diagnostics_float_cursor}), - \ lsp#callbag#tap({_->s:hide_float()}), \ lsp#callbag#debounceTime(g:lsp_diagnostics_float_delay), \ lsp#callbag#map({_->{'bufnr': bufnr('%'), 'curpos': getcurpos()[0:2], 'changedtick': b:changedtick }}), \ lsp#callbag#distinctUntilChanged({a,b -> a['bufnr'] == b['bufnr'] && a['curpos'] == b['curpos'] && a['changedtick'] == b['changedtick']}), diff --git a/doc/vim-lsp.txt b/doc/vim-lsp.txt index f47f6ac4c..2acabca33 100644 --- a/doc/vim-lsp.txt +++ b/doc/vim-lsp.txt @@ -30,6 +30,8 @@ CONTENTS *vim-lsp-contents* g:lsp_diagnostics_echo_delay |g:lsp_diagnostics_echo_delay| g:lsp_diagnostics_float_cursor |g:lsp_diagnostics_float_cursor| g:lsp_diagnostics_float_delay |g:lsp_diagnostics_float_delay| + g:lsp_diagnostics_float_close_on_hold + |g:lsp_diagnostics_float_close_on_hold| g:lsp_diagnostics_float_insert_mode_enabled |g:lsp_diagnostics_float_insert_mode_enabled| g:lsp_diagnostics_highlights_enabled @@ -535,6 +537,18 @@ g:lsp_diagnostics_float_delay *g:lsp_diagnostics_float_delay* let g:lsp_diagnostics_float_delay = 200 let g:lsp_diagnostics_float_delay = 1000 +g:lsp_diagnostics_float_close_on_hold + *g:lsp_diagnostics_float_close_on_hold* + Type: |Boolean| + Default: `1` + + Indicates whether to close float of diagnostic error when is + triggered. Setting this to 0 will allow float to stay open until cursor + is moved or mode is changed. + + Example: > + let g:lsp_diagnostics_float_close_on_hold = 0 + g:lsp_diagnostics_float_insert_mode_enabled *g:lsp_diagnostics_float_insert_mode_enabled* Type: |Boolean| diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 11a2b4428..39596006d 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -21,6 +21,7 @@ let g:lsp_diagnostics_echo_cursor = get(g:, 'lsp_diagnostics_echo_cursor', 0) let g:lsp_diagnostics_echo_delay = get(g:, 'lsp_diagnostics_echo_delay', 500) let g:lsp_diagnostics_float_cursor = get(g:, 'lsp_diagnostics_float_cursor', 0) let g:lsp_diagnostics_float_delay = get(g:, 'lsp_diagnostics_float_delay', 500) +let g:lsp_diagnostics_float_close_on_hold = get(g:, 'lsp_diagnostics_float_close_on_hold', 1) let g:lsp_diagnostics_float_insert_mode_enabled = get(g:, 'lsp_diagnostics_float_insert_mode_enabled', 1) let g:lsp_diagnostics_highlights_enabled = get(g:, 'lsp_diagnostics_highlights_enabled', lsp#utils#_has_highlights()) let g:lsp_diagnostics_highlights_insert_mode_enabled = get(g:, 'lsp_diagnostics_highlights_insert_mode_enabled', 1)