Skip to content

Commit

Permalink
Merge pull request #482 from nickspoons/wrap-diagnostics
Browse files Browse the repository at this point in the history
Add LspDiag nextWrap and prevWrap command args
  • Loading branch information
yegappan authored May 8, 2024
2 parents 8255965 + e9f337e commit 07a536f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ Command|Description
:LspDiag highlight disable|Disable diagnostic message highlights.
:LspDiag highlight enable|Enable diagnostic message highlights.
:LspDiag next|Jump to the next diagnostic message after the current position.
:LspDiag nextWrap|Jump to the next diagnostic message after the current position, wrapping to the first message when the last message is reached.
:LspDiag prev|Jump to the previous diagnostic message before the current position.
:LspDiag prevWrap|Jump to the previous diagnostic message before the current position, wrapping to the last message when the first message is reached.
:LspDiag show|Display the diagnostics messages from the language server for the current buffer in a new location list.
:LspDocumentSymbol|Display the symbols in the current file in a popup menu and jump to the selected symbol.
:LspFold|Fold the current file.
Expand Down
15 changes: 10 additions & 5 deletions autoload/lsp/diag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,13 @@ export def LspDiagsJump(which: string, a_count: number = 0): void
var count = a_count > 1 ? a_count : 1
var curlnum: number = line('.')
var curcol: number = charcol('.')
for diag in (which == 'next' || which == 'here') ?
for diag in (which == 'next' || which == 'nextWrap' || which == 'here') ?
diags : diags->copy()->reverse()
var d_start = diag.range.start
var lnum = d_start.line + 1
var col = util.GetCharIdxWithoutCompChar(bnr, d_start) + 1
if (which == 'next' && (lnum > curlnum || lnum == curlnum && col > curcol))
|| (which == 'prev' && (lnum < curlnum || lnum == curlnum
if ((which == 'next' || which == 'nextWrap') && (lnum > curlnum || lnum == curlnum && col > curcol))
|| ((which == 'prev' || which == 'prevWrap') && (lnum < curlnum || lnum == curlnum
&& col < curcol))
|| (which == 'here' && (lnum == curlnum && col >= curcol))

Expand All @@ -797,17 +797,22 @@ export def LspDiagsJump(which: string, a_count: number = 0): void
endfor

# If [count] exceeded the remaining diags
if which == 'next' && a_count > 1 && a_count != count
if ((which == 'next' || which == 'nextWrap') && a_count > 1 && a_count != count)
JumpDiag(diags[-1])
return
endif

# If [count] exceeded the previous diags
if which == 'prev' && a_count > 1 && a_count != count
if ((which == 'prev' || which == 'prevWrap') && a_count > 1 && a_count != count)
JumpDiag(diags[0])
return
endif

if which == 'nextWrap' || which == 'prevWrap'
JumpDiag(diags[which == 'nextWrap' ? 0 : -1])
return
endif

if which == 'here'
util.WarnMsg('No more diagnostics found on this line')
else
Expand Down
8 changes: 6 additions & 2 deletions autoload/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,8 @@ enddef
export def LspDiagComplete(arglead: string, cmdline: string, cursorPos: number): list<string>
var wordBegin = -1
var wordEnd = -1
var l = ['first', 'current', 'here', 'highlight', 'last', 'next', 'prev',
'show']
var l = ['first', 'current', 'here', 'highlight', 'last', 'next', 'nextWrap',
'prev', 'prevWrap', 'show']

# Skip the command name
var i = cmdline->stridx(' ', 0)
Expand Down Expand Up @@ -1209,8 +1209,12 @@ export def LspDiagCmd(args: string, cmdCount: number, force: bool)
diag.LspDiagsJump('last', 0)
elseif args == 'next'
diag.LspDiagsJump('next', cmdCount)
elseif args == 'nextWrap'
diag.LspDiagsJump('nextWrap', cmdCount)
elseif args == 'prev'
diag.LspDiagsJump('prev', cmdCount)
elseif args == 'prevWrap'
diag.LspDiagsJump('prevWrap', cmdCount)
elseif args == 'show'
ShowDiagnostics()
else
Expand Down
8 changes: 8 additions & 0 deletions doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ The following commands are provided:
buffer.
:LspDiag next Jump to the next diagnostic message for the current
buffer after the current cursor position.
:LspDiag nextWrap Jump to the next diagnostic message for the current
buffer after the current cursor position.
Wrap back to the first message when no more messages
are found.
:LspDiag prev Jump to the previous diagnostic message for the
current buffer before the current current position.
:LspDiag prevWrap Jump to the previous diagnostic message for the
current buffer before the current current position.
Wrap back to the last message when no previous
messages are found.
:LspDiag show Display the diagnostics messages from the language
server for the current buffer in a location list.
:LspDocumentSymbol Display the symbols in the current file in a popup
Expand Down
2 changes: 2 additions & 0 deletions plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(<bang>false)
command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
command! -nargs=0 -bar LspDiagLast lsp.JumpToDiag('last')
command! -nargs=0 -bar -count=1 LspDiagNext lsp.JumpToDiag('next', <count>)
command! -nargs=0 -bar -count=1 LspDiagNextWrap lsp.JumpToDiag('nextWrap', <count>)
command! -nargs=0 -bar -count=1 LspDiagPrev lsp.JumpToDiag('prev', <count>)
command! -nargs=0 -bar -count=1 LspDiagPrevWrap lsp.JumpToDiag('prevWrap', <count>)
command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here')
command! -nargs=0 -bar LspDocumentSymbol lsp.ShowDocSymbols()
Expand Down
9 changes: 8 additions & 1 deletion test/clangd_tests.vim
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ def g:Test_LspDiag_Multi()
var output = execute('LspDiag prev')->split("\n")
assert_equal('Warn: No more diagnostics found', output[0])

assert_equal('', execute('LspDiag prevWrap'))
assert_equal([2, 9], [line('.'), col('.')])

cursor(2, 1)
assert_equal('', execute('LspDiag first'))
assert_equal([1, 5], [line('.'), col('.')])
Expand All @@ -519,6 +522,10 @@ def g:Test_LspDiag_Multi()
cursor(1, 1)
assert_equal('', execute('LspDiag last'))
assert_equal([2, 9], [line('.'), col('.')])
assert_equal('', execute('LspDiag nextWrap'))
assert_equal([1, 5], [line('.'), col('.')])
assert_equal('', execute('LspDiag nextWrap'))
assert_equal([1, 9], [line('.'), col('.')])
popup_clear()

# Test for :LspDiag here on a line with multiple diagnostics
Expand Down Expand Up @@ -1625,7 +1632,7 @@ def g:Test_LspDiagsSubcmd()
new XLspDiagsSubCmd.raku

feedkeys(":LspDiag \<C-A>\<CR>", 'xt')
assert_equal('LspDiag first current here highlight last next prev show', @:)
assert_equal('LspDiag first current here highlight last next nextWrap prev prevWrap show', @:)
feedkeys(":LspDiag highlight \<C-A>\<CR>", 'xt')
assert_equal('LspDiag highlight enable disable', @:)
assert_equal(['Error: :LspDiag - Unsupported argument "xyz"'],
Expand Down

0 comments on commit 07a536f

Please sign in to comment.