Skip to content

Commit

Permalink
Send diagnostics along with a code actions request (#90)
Browse files Browse the repository at this point in the history
Store the original LSP representation of a diagnostic along with the internal representation and add a method to find all of the original diagnostics for a given line.

Include all diagnostics for the current line along with code actions requests.
  • Loading branch information
natebosch authored Jun 5, 2018
1 parent 3594046 commit 70bc0d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Enable incremental sync by default.
- Enable apply edit by default.
- Improve the preview height for hover text which has few lines but they wrap.
- Bug Fix: Include diagnostics for the current line with code actions requests.

# 0.2.10

Expand Down
15 changes: 14 additions & 1 deletion autoload/lsc/diagnostics.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function! s:Convert(diagnostic) abort
let message = message.' ['.a:diagnostic.code.']'
endif
return {'group': group, 'message': message, 'type': type,
\ 'ranges': lsc#convert#rangeToHighlights(a:diagnostic.range)}
\ 'ranges': lsc#convert#rangeToHighlights(a:diagnostic.range),
\ 'lsp': a:diagnostic}
endfunction

function! lsc#diagnostics#clean(filetype) abort
Expand Down Expand Up @@ -235,3 +236,15 @@ function! lsc#diagnostics#underCursor() abort
endfor
return closest_diagnostic
endfunction

" Returns the original LSP representation of diagnostics on a line.
function! lsc#diagnostics#forLine(file, line) abort
let l:result = []
let l:file_diagnostics = lsc#diagnostics#forFile(a:file)
if has_key(l:file_diagnostics, a:line)
for l:diagnostic in l:file_diagnostics[a:line]
call add(l:result, l:diagnostic.lsp)
endfor
endif
return l:result
endfunction
3 changes: 2 additions & 1 deletion autoload/lsc/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function! s:TextDocumentRangeParams() abort
\ 'range': {
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
\ 'context': {'diagnostics': []}
\ 'context': {'diagnostics':
\ lsc#diagnostics#forLine(expand('%:p'), line('.'))}
\}
endfunction

Expand Down

0 comments on commit 70bc0d6

Please sign in to comment.