Skip to content

Commit 33e94d9

Browse files
committed
Support funcref in LanguageClient_diagnosticsList
1 parent be50c97 commit 33e94d9

File tree

5 files changed

+233
-135
lines changed

5 files changed

+233
-135
lines changed

Diff for: autoload/LanguageClient.vim

+10-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ function! s:hasSnippetSupport() abort
117117
return 0
118118
endfunction
119119

120+
function! s:getStringOrFuncref(name, default) abort
121+
if type(get(g:, a:name, a:default)) is s:TYPE.funcref
122+
return string(get(g:, a:name, a:default))
123+
else
124+
return get(g:, a:name, a:default)
125+
endif
126+
endfunction
127+
120128
function! s:getSelectionUI() abort
121129
if type(get(g:, 'LanguageClient_selectionUI', v:null)) is s:TYPE.funcref
122130
return 'funcref'
@@ -1236,11 +1244,11 @@ function! LanguageClient#handleVimLeavePre() abort
12361244
endtry
12371245
endfunction
12381246

1239-
function! s:LanguageClient_FZFSinkLocation(line) abort
1247+
function! g:LanguageClient_FZFSinkLocation(line) abort
12401248
return LanguageClient#Notify('LanguageClient_FZFSinkLocation', [a:line])
12411249
endfunction
12421250

1243-
function! LanguageClient_FZFSinkCommand(selection) abort
1251+
function! g:LanguageClient_FZFSinkCommand(selection) abort
12441252
return LanguageClient#Notify('LanguageClient_FZFSinkCommand', {
12451253
\ 'selection': a:selection,
12461254
\ })

Diff for: doc/LanguageClient.txt

+43-46
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,49 @@ Valid options: "off" | "messages" | "verbose"
207207
List used to fill diagnostic messages.
208208

209209
Default: "Quickfix"
210-
Valid options: "Quickfix" | "Location" | "Disabled"
210+
Valid options: "Quickfix" | "Location" | "Disabled" | |Funcref|
211+
212+
If you use a |Funcref|, the referenced function should have two arguments
213+
(filename, diagnostics). filename is the name of the file of which the
214+
diagnostics correspond to, and diagnostics is the list of diagnostics for said
215+
file. Those diagnostics are as specified in the LSP specification.
216+
217+
For example, if you wanted to use `dense-analysis/ale` to display diagnostics
218+
instead of this plugin you could use something like this:
219+
220+
```
221+
function! DisplayDiagnostics(filename, diagnostics) abort
222+
let s:diagnostics = []
223+
224+
for d in a:diagnostics
225+
let s:severity = 'I'
226+
if d.severity == 1
227+
let s:severity = 'E'
228+
elseif d.severity == 2
229+
let s:severity = 'W'
230+
endif
231+
232+
call add(s:diagnostics, {
233+
\ "filename": a:filename,
234+
\ "text": d.message,
235+
\ "lnum": d.range.start.line + 1,
236+
\ "end_lnum": d.range.end.line + 1,
237+
\ "col": d.range.end.character,
238+
\ "end_col": d.range.end.character,
239+
\ "type": s:severity,
240+
\ })
241+
endfor
242+
243+
call ale#other_source#ShowResults(bufnr('%'), 'LanguageClientNeovim', s:diagnostics)
244+
endfunction
245+
246+
let g:LanguageClient_diagnosticsDisplayFuncref = function('DisplayDiagnostics')
247+
```
248+
249+
Keep in mind that to complete the integration between `ale` and
250+
`LanguageClient-neovim` you need to add `LanguageClientNeovim` (or the name of
251+
the linter you used in the call to ShowResults) to the list of linters to be
252+
used in `ale`.
211253

212254
2.10 g:LanguageClient_diagnosticsEnable *g:LanguageClient_diagnosticsEnable*
213255

@@ -635,51 +677,6 @@ Highlight group to be used for code lens.
635677

636678
Default: 'Comment'
637679

638-
2.42 g:LanguageClient_diagnosticsDisplayFuncref *g:LanguageClient_diagnosticsDisplayFuncref*
639-
640-
If set, LanguageClient-neovim will call this function instead of setting the diagnostics signs. This
641-
is useful to delegate the display of diagnostics to other engines. The function is called with two
642-
arguments, the first one is the file name of which the diagnostics correspond to, and the seconds one
643-
is the list of diagnostics for said file. Those diagnostics are as specified in the LSP specification.
644-
645-
For example, if you wanted to use `dense-analysis/ale` to display diagnostics instead of this plugin
646-
you could use something like this:
647-
648-
```
649-
function! g:DisplayDiagnostics(filename, diagnostics) abort
650-
let s:diagnostics = []
651-
652-
for d in a:diagnostics
653-
let s:severity = 'I'
654-
if d.severity == 1
655-
let s:severity = 'E'
656-
elseif d.severity == 2
657-
let s:severity = 'W'
658-
endif
659-
660-
call add(s:diagnostics, {
661-
\ "filename": a:filename,
662-
\ "text": d.message,
663-
\ "lnum": d.range.start.line + 1,
664-
\ "end_lnum": d.range.end.line + 1,
665-
\ "col": d.range.end.character,
666-
\ "end_col": d.range.end.character,
667-
\ "type": s:severity,
668-
\ })
669-
endfor
670-
671-
call ale#other_source#ShowResults(bufnr('%'), 'LanguageClientNeovim', s:diagnostics)
672-
endfunction
673-
674-
let g:LanguageClient_diagnosticsDisplayFuncref = 'g:DisplayDiagnostics'
675-
```
676-
677-
Keep in mind that to complete the integration between `ale` and `LanguageClient-neovim` you need to
678-
add `LanguageClientNeovim` (or the name of the linter you used in the call to ShowResults) to the list
679-
of linters to be used in `ale`.
680-
681-
Default: v:null
682-
683680
==============================================================================
684681
3. Commands *LanguageClientCommands*
685682

0 commit comments

Comments
 (0)