Skip to content

Commit

Permalink
Support funcref in LanguageClient_diagnosticsList
Browse files Browse the repository at this point in the history
  • Loading branch information
martskins committed Oct 22, 2020
1 parent be50c97 commit 33e94d9
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 135 deletions.
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
89 changes: 43 additions & 46 deletions 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 Expand Up @@ -635,51 +677,6 @@ Highlight group to be used for code lens.

Default: 'Comment'

2.42 g:LanguageClient_diagnosticsDisplayFuncref *g:LanguageClient_diagnosticsDisplayFuncref*

If set, LanguageClient-neovim will call this function instead of setting the diagnostics signs. This
is useful to delegate the display of diagnostics to other engines. The function is called with two
arguments, the first one is the file name of which the diagnostics correspond to, and the seconds one
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! g: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 = 'g: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`.

Default: v:null

==============================================================================
3. Commands *LanguageClientCommands*

Expand Down
Loading

0 comments on commit 33e94d9

Please sign in to comment.