Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for diagnostics display funcref for more flexible integration #1101

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions autoload/LanguageClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ function! s:hasSnippetSupport() abort
return 0
endfunction

function! s:getStringOrFuncref(name, default) abort
if type(get(g:, a:name, a:default)) is s:TYPE.funcref
return string(get(g:, a:name, a:default))
else
return get(g:, a:name, a:default)
endif
endfunction

function! s:getSelectionUI() abort
if type(get(g:, 'LanguageClient_selectionUI', v:null)) is s:TYPE.funcref
return 'funcref'
Expand Down Expand Up @@ -1236,11 +1244,11 @@ function! LanguageClient#handleVimLeavePre() abort
endtry
endfunction

function! s:LanguageClient_FZFSinkLocation(line) abort
function! g:LanguageClient_FZFSinkLocation(line) abort
return LanguageClient#Notify('LanguageClient_FZFSinkLocation', [a:line])
endfunction

function! LanguageClient_FZFSinkCommand(selection) abort
function! g:LanguageClient_FZFSinkCommand(selection) abort
return LanguageClient#Notify('LanguageClient_FZFSinkCommand', {
\ 'selection': a:selection,
\ })
Expand Down
44 changes: 43 additions & 1 deletion doc/LanguageClient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,49 @@ Valid options: "off" | "messages" | "verbose"
List used to fill diagnostic messages.

Default: "Quickfix"
Valid options: "Quickfix" | "Location" | "Disabled"
Valid options: "Quickfix" | "Location" | "Disabled" | |Funcref|

If you use a |Funcref|, the referenced function should have two arguments
(filename, diagnostics). filename is the name of the file of which the
diagnostics correspond to, and diagnostics is the list of diagnostics for said
file. Those diagnostics are as specified in the LSP specification.

For example, if you wanted to use `dense-analysis/ale` to display diagnostics
instead of this plugin you could use something like this:

```
function! DisplayDiagnostics(filename, diagnostics) abort
let s:diagnostics = []

for d in a:diagnostics
let s:severity = 'I'
if d.severity == 1
let s:severity = 'E'
elseif d.severity == 2
let s:severity = 'W'
endif

call add(s:diagnostics, {
\ "filename": a:filename,
\ "text": d.message,
\ "lnum": d.range.start.line + 1,
\ "end_lnum": d.range.end.line + 1,
\ "col": d.range.end.character,
\ "end_col": d.range.end.character,
\ "type": s:severity,
\ })
endfor

call ale#other_source#ShowResults(bufnr('%'), 'LanguageClientNeovim', s:diagnostics)
endfunction

let g:LanguageClient_diagnosticsDisplayFuncref = function('DisplayDiagnostics')
```

Keep in mind that to complete the integration between `ale` and
`LanguageClient-neovim` you need to add `LanguageClientNeovim` (or the name of
the linter you used in the call to ShowResults) to the list of linters to be
used in `ale`.

2.10 g:LanguageClient_diagnosticsEnable *g:LanguageClient_diagnosticsEnable*

Expand Down
Loading