mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
Jumping to diagnostics with command args '-nowrap' (#770)
* Add func 'lsp#utils#parse_command_options' * Add wrap option to jumping to diagnostic * Update doc * Fix lint error * Remove debug code
This commit is contained in:
@@ -106,28 +106,36 @@ function! s:severity_of(diagnostic) abort
|
||||
return get(a:diagnostic, 'severity', 1)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#next_error() abort
|
||||
function! lsp#ui#vim#diagnostics#next_error(...) abort
|
||||
let l:diagnostics = filter(s:get_all_buffer_diagnostics(),
|
||||
\ {_, diagnostic -> s:severity_of(diagnostic) ==# 1 })
|
||||
call s:next_diagnostic(l:diagnostics)
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
call s:next_diagnostic(l:diagnostics, l:options)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#next_warning() abort
|
||||
function! lsp#ui#vim#diagnostics#next_warning(...) abort
|
||||
let l:diagnostics = filter(s:get_all_buffer_diagnostics(),
|
||||
\ {_, diagnostic -> s:severity_of(diagnostic) ==# 2 })
|
||||
call s:next_diagnostic(l:diagnostics)
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
call s:next_diagnostic(l:diagnostics, l:options)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#next_diagnostic() abort
|
||||
call s:next_diagnostic(s:get_all_buffer_diagnostics())
|
||||
function! lsp#ui#vim#diagnostics#next_diagnostic(...) abort
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
call s:next_diagnostic(s:get_all_buffer_diagnostics(), l:options)
|
||||
endfunction
|
||||
|
||||
function! s:next_diagnostic(diagnostics) abort
|
||||
function! s:next_diagnostic(diagnostics, options) abort
|
||||
if !len(a:diagnostics)
|
||||
return
|
||||
endif
|
||||
call sort(a:diagnostics, 's:compare_diagnostics')
|
||||
|
||||
let l:wrap = 1
|
||||
if has_key(a:options, 'wrap')
|
||||
let l:wrap = a:options['wrap']
|
||||
endif
|
||||
|
||||
let l:view = winsaveview()
|
||||
let l:next_line = 0
|
||||
let l:next_col = 0
|
||||
@@ -142,6 +150,9 @@ function! s:next_diagnostic(diagnostics) abort
|
||||
endfor
|
||||
|
||||
if l:next_line == 0
|
||||
if !l:wrap
|
||||
return
|
||||
endif
|
||||
" Wrap to start
|
||||
let [l:next_line, l:next_col] = lsp#utils#position#lsp_to_vim('%', a:diagnostics[0]['range']['start'])
|
||||
let l:next_col -= 1
|
||||
@@ -163,28 +174,36 @@ function! s:next_diagnostic(diagnostics) abort
|
||||
call winrestview(l:view)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#previous_error() abort
|
||||
function! lsp#ui#vim#diagnostics#previous_error(...) abort
|
||||
let l:diagnostics = filter(s:get_all_buffer_diagnostics(),
|
||||
\ {_, diagnostic -> s:severity_of(diagnostic) ==# 1 })
|
||||
call s:previous_diagnostic(l:diagnostics)
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
call s:previous_diagnostic(l:diagnostics, l:options)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#previous_warning() abort
|
||||
function! lsp#ui#vim#diagnostics#previous_warning(...) abort
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
let l:diagnostics = filter(s:get_all_buffer_diagnostics(),
|
||||
\ {_, diagnostic -> s:severity_of(diagnostic) ==# 2 })
|
||||
call s:previous_diagnostic(l:diagnostics)
|
||||
call s:previous_diagnostic(l:diagnostics, l:options)
|
||||
endfunction
|
||||
|
||||
function! lsp#ui#vim#diagnostics#previous_diagnostic() abort
|
||||
call s:previous_diagnostic(s:get_all_buffer_diagnostics())
|
||||
function! lsp#ui#vim#diagnostics#previous_diagnostic(...) abort
|
||||
let l:options = lsp#utils#parse_command_options(a:000)
|
||||
call s:previous_diagnostic(s:get_all_buffer_diagnostics(), l:options)
|
||||
endfunction
|
||||
|
||||
function! s:previous_diagnostic(diagnostics) abort
|
||||
function! s:previous_diagnostic(diagnostics, options) abort
|
||||
if !len(a:diagnostics)
|
||||
return
|
||||
endif
|
||||
call sort(a:diagnostics, 's:compare_diagnostics')
|
||||
|
||||
let l:wrap = 1
|
||||
if has_key(a:options, 'wrap')
|
||||
let l:wrap = a:options['wrap']
|
||||
endif
|
||||
|
||||
let l:view = winsaveview()
|
||||
let l:next_line = 0
|
||||
let l:next_col = 0
|
||||
@@ -201,6 +220,9 @@ function! s:previous_diagnostic(diagnostics) abort
|
||||
endwhile
|
||||
|
||||
if l:next_line == 0
|
||||
if !l:wrap
|
||||
return
|
||||
endif
|
||||
" Wrap to end
|
||||
let [l:next_line, l:next_col] = lsp#utils#position#lsp_to_vim('%', a:diagnostics[-1]['range']['start'])
|
||||
let l:next_col -= 1
|
||||
|
||||
@@ -329,3 +329,12 @@ function! lsp#utils#_split_by_eol(text) abort
|
||||
return split(a:text, '\r\n\|\r\|\n', v:true)
|
||||
endfunction
|
||||
|
||||
" parse command options like "-key" or "-key=value"
|
||||
function! lsp#utils#parse_command_options(params) abort
|
||||
let l:result = {}
|
||||
for l:param in a:params
|
||||
let l:match = matchlist(l:param, '-\{1,2}\zs\([^=]*\)\(=\(.*\)\)\?\m')
|
||||
let l:result[l:match[1]] = l:match[3]
|
||||
endfor
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
@@ -1093,21 +1093,24 @@ Gets the hover information and displays it in the |preview-window|.
|
||||
automatically on cursormove if not focused and can be closed with <esc> if
|
||||
focused.
|
||||
|
||||
LspNextDiagnostic *:LspNextDiagnostic*
|
||||
LspNextDiagnostic [-wrap=0] *:LspNextDiagnostic*
|
||||
|
||||
Jump to Next diagnostics including error, warning, information, hint.
|
||||
With '-wrap=0', stop wrapping around the end of file.
|
||||
|
||||
LspNextError *:LspNextError*
|
||||
LspNextError [-wrap=0] *:LspNextError*
|
||||
|
||||
Jump to Next err diagnostics
|
||||
With '-wrap=0', stop wrapping around the end of file.
|
||||
|
||||
LspNextReference *:LspNextReference*
|
||||
|
||||
Jump to the next reference of the symbol under cursor.
|
||||
|
||||
LspNextWarning :LspNextWarning*
|
||||
LspNextWarning [-wrap=0] :LspNextWarning*
|
||||
|
||||
Jump to Next warning diagnostics
|
||||
With '-wrap=0', stop wrapping around the end of file.
|
||||
|
||||
LspPeekDeclaration *:LspPeekDeclaration*
|
||||
|
||||
@@ -1137,21 +1140,24 @@ Like |:LspTypeDefinition|, but opens the type definition in the
|
||||
|
||||
Also see |g:lsp_peek_alignment| and |g:lsp_preview_float|.
|
||||
|
||||
LspPreviousDiagnostic *:LspPreviousDiagnostic*
|
||||
LspPreviousDiagnostic [-wrap=0] *:LspPreviousDiagnostic*
|
||||
|
||||
Jump to Previous diagnostics including error, warning, information, hint.
|
||||
With '-wrap=0', stop wrapping around the top of file.
|
||||
|
||||
LspPreviousError *:LspPreviousError*
|
||||
LspPreviousError [-wrap=0] *:LspPreviousError*
|
||||
|
||||
Jump to Previous err diagnostics
|
||||
With '-wrap=0', stop wrapping around the top of file.
|
||||
|
||||
LspPreviousReference *:LspPreviousReference*
|
||||
|
||||
Jump to the previous reference of the symbol under cursor.
|
||||
|
||||
LspPreviousWarning *:LspPreviousWarning*
|
||||
LspPreviousWarning [-wrap=0] *:LspPreviousWarning*
|
||||
|
||||
Jump to Previous warning diagnostics
|
||||
With '-wrap=0', stop wrapping around the top of file.
|
||||
|
||||
LspImplementation *:LspImplementation*
|
||||
|
||||
@@ -1283,15 +1289,21 @@ Available plug mappings are following:
|
||||
nnoremap <plug>(lsp-document-diagnostics)
|
||||
nnoremap <plug>(lsp-hover)
|
||||
nnoremap <plug>(lsp-next-diagnostic)
|
||||
nnoremap <plug>(lsp-next-diagnostic-nowrap)
|
||||
nnoremap <plug>(lsp-next-error)
|
||||
nnoremap <plug>(lsp-next-error-nowrap)
|
||||
nnoremap <plug>(lsp-next-reference)
|
||||
nnoremap <plug>(lsp-next-warning)
|
||||
nnoremap <plug>(lsp-next-warning-nowrap)
|
||||
nnoremap <plug>(lsp-preview-close)
|
||||
nnoremap <plug>(lsp-preview-focus)
|
||||
nnoremap <plug>(lsp-previous-diagnostic)
|
||||
nnoremap <plug>(lsp-previous-diagnostic-nowrap)
|
||||
nnoremap <plug>(lsp-previous-error)
|
||||
nnoremap <plug>(lsp-previous-error-nowrap)
|
||||
nnoremap <plug>(lsp-previous-reference)
|
||||
nnoremap <plug>(lsp-previous-warning)
|
||||
nnoremap <plug>(lsp-previous-warning-nowrap)
|
||||
nnoremap <plug>(lsp-references)
|
||||
nnoremap <plug>(lsp-rename)
|
||||
nnoremap <plug>(lsp-workspace-symbol)
|
||||
|
||||
@@ -72,12 +72,12 @@ command! LspPeekDefinition call lsp#ui#vim#definition(1)
|
||||
command! LspDocumentSymbol call lsp#ui#vim#document_symbol()
|
||||
command! LspDocumentDiagnostics call lsp#ui#vim#diagnostics#document_diagnostics()
|
||||
command! -nargs=? -complete=customlist,lsp#utils#empty_complete LspHover call lsp#ui#vim#hover#get_hover_under_cursor()
|
||||
command! LspNextError call lsp#ui#vim#diagnostics#next_error()
|
||||
command! LspPreviousError call lsp#ui#vim#diagnostics#previous_error()
|
||||
command! LspNextWarning call lsp#ui#vim#diagnostics#next_warning()
|
||||
command! LspPreviousWarning call lsp#ui#vim#diagnostics#previous_warning()
|
||||
command! LspNextDiagnostic call lsp#ui#vim#diagnostics#next_diagnostic()
|
||||
command! LspPreviousDiagnostic call lsp#ui#vim#diagnostics#previous_diagnostic()
|
||||
command! -nargs=* LspNextError call lsp#ui#vim#diagnostics#next_error(<f-args>)
|
||||
command! -nargs=* LspPreviousError call lsp#ui#vim#diagnostics#previous_error(<f-args>)
|
||||
command! -nargs=* LspNextWarning call lsp#ui#vim#diagnostics#next_warning(<f-args>)
|
||||
command! -nargs=* LspPreviousWarning call lsp#ui#vim#diagnostics#previous_warning(<f-args>)
|
||||
command! -nargs=* LspNextDiagnostic call lsp#ui#vim#diagnostics#next_diagnostic(<f-args>)
|
||||
command! -nargs=* LspPreviousDiagnostic call lsp#ui#vim#diagnostics#previous_diagnostic(<f-args>)
|
||||
command! LspReferences call lsp#ui#vim#references()
|
||||
command! LspRename call lsp#ui#vim#rename()
|
||||
command! LspTypeDefinition call lsp#ui#vim#type_definition(0, <q-mods>)
|
||||
@@ -110,11 +110,17 @@ nnoremap <plug>(lsp-hover) :<c-u>call lsp#ui#vim#hover#get_hover_under_cursor()<
|
||||
nnoremap <plug>(lsp-preview-close) :<c-u>call lsp#ui#vim#output#closepreview()<cr>
|
||||
nnoremap <plug>(lsp-preview-focus) :<c-u>call lsp#ui#vim#output#focuspreview()<cr>
|
||||
nnoremap <plug>(lsp-next-error) :<c-u>call lsp#ui#vim#diagnostics#next_error()<cr>
|
||||
nnoremap <plug>(lsp-next-error-nowrap) :<c-u>call lsp#ui#vim#diagnostics#next_error("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-previous-error) :<c-u>call lsp#ui#vim#diagnostics#previous_error()<cr>
|
||||
nnoremap <plug>(lsp-previous-error-nowrap) :<c-u>call lsp#ui#vim#diagnostics#previous_error("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-next-warning) :<c-u>call lsp#ui#vim#diagnostics#next_warning()<cr>
|
||||
nnoremap <plug>(lsp-next-warning-nowrap) :<c-u>call lsp#ui#vim#diagnostics#next_warning("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-previous-warning) :<c-u>call lsp#ui#vim#diagnostics#previous_warning()<cr>
|
||||
nnoremap <plug>(lsp-previous-warning-nowrap) :<c-u>call lsp#ui#vim#diagnostics#previous_warning("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-next-diagnostic) :<c-u>call lsp#ui#vim#diagnostics#next_diagnostic()<cr>
|
||||
nnoremap <plug>(lsp-next-diagnostic-nowrap) :<c-u>call lsp#ui#vim#diagnostics#next_diagnostic("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-previous-diagnostic) :<c-u>call lsp#ui#vim#diagnostics#previous_diagnostic()<cr>
|
||||
nnoremap <plug>(lsp-previous-diagnostic-nowrap) :<c-u>call lsp#ui#vim#diagnostics#previous_diagnostic("--nowrap")<cr>
|
||||
nnoremap <plug>(lsp-references) :<c-u>call lsp#ui#vim#references()<cr>
|
||||
nnoremap <plug>(lsp-rename) :<c-u>call lsp#ui#vim#rename()<cr>
|
||||
nnoremap <plug>(lsp-type-definition) :<c-u>call lsp#ui#vim#type_definition(0)<cr>
|
||||
|
||||
Reference in New Issue
Block a user