Skip to content

Commit d78d219

Browse files
allow to enable or disable diagnostics per buffer (#1005)
1 parent 268341f commit d78d219

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

autoload/lsp.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,16 @@ function! s:send_didchange_queue(...) abort
11151115
let s:didchange_queue = []
11161116
endfunction
11171117

1118+
function! lsp#enable_diagnostics_for_buffer(...) abort
1119+
let l:bufnr = a:0 > 0 ? a:1 : bufnr('%')
1120+
call lsp#internal#diagnostics#state#_enable_for_buffer(l:bufnr)
1121+
endfunction
1122+
1123+
function! lsp#disable_diagnostics_for_buffer(...) abort
1124+
let l:bufnr = a:0 > 0 ? a:1 : bufnr('%')
1125+
call lsp#internal#diagnostics#state#_disable_for_buffer(l:bufnr)
1126+
endfunction
1127+
11181128
" Return dict with diagnostic counts for current buffer
11191129
" { 'error': 1, 'warning': 0, 'information': 0, 'hint': 0 }
11201130
function! lsp#get_buffer_diagnostics_counts() abort

doc/vim-lsp.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ CONTENTS *vim-lsp-contents*
7979
lsp#stop_server |lsp#stop_server()|
8080
lsp#utils#find_nearest_parent_file_directory()
8181
|lsp#utils#find_nearest_parent_file_directory()|
82+
lsp#enable_diagnostics_for_buffer() |lsp#enable_diagnostics_for_buffer()|
83+
lsp#disable_diagnostics_for_buffer()|lsp#disable_diagnostics_for_buffer()|
8284
lsp#get_buffer_diagnostics_counts() |lsp#get_buffer_diagnostics_counts()|
8385
lsp#get_buffer_first_error_line() |lsp#get_buffer_first_error_line()|
8486
lsp#get_progress() |lsp#get_progress()|
@@ -1268,6 +1270,34 @@ This method is mainly used to generate 'root_uri' when registering server.
12681270
* If there is not directory with the specific files or diretories
12691271
found, the method will return an empty string.
12701272

1273+
lsp#enable_diagnostics_for_buffer() *lsp#enable_diagnotics_for_buffer()*
1274+
1275+
Re-enable diagnsostics for the specified buffer. By default diagnostics are
1276+
enabled for all buffers.
1277+
1278+
Example: >
1279+
:call lsp#enable_diagnostics_for_buffer()
1280+
:call lsp#enable_diagnostics_for_buffer(bufnr('%'))
1281+
1282+
lsp#disable_diagnostics_for_buffer() *lsp#disable_diagnostics_for_buffer()*
1283+
1284+
Diable diagnostics for the specified buffer. By default diagnostics are
1285+
enabled for all buffers.
1286+
1287+
Example: >
1288+
:call lsp#enable_diagnostics_for_buffer()
1289+
:call lsp#enable_diagnostics_for_buffer(bufnr('%'))
1290+
1291+
Diagnostics can be disabled for buffer to temporarily avoid conflicts with
1292+
other plugins.
1293+
1294+
Example: >
1295+
augroup LspEasyMotion
1296+
autocmd!
1297+
autocmd User EasyMotionPromptBegin call lsp#disable_diagnostics_for_buffer()<CR>
1298+
autocmd User EasyMotionPromptEnd call lsp#enable_diagnostics_for_buffer()<CR>
1299+
augroup END
1300+
12711301
lsp#get_buffer_diagnostics_counts() *lsp#get_buffer_diagnostics_counts()*
12721302

12731303
Get dict with diagnostic counts for current buffer. Useful e.g. for display

0 commit comments

Comments
 (0)