Skip to content

Commit 91755cd

Browse files
committed
Refine LSP wrapper
1 parent abf5ad2 commit 91755cd

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

core/autoload/spacevim/lang/util.vim

+21-33
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,33 @@ function! spacevim#lang#util#InferExecutable() abort
1212
return executable(l:exe) ? l:exe : ''
1313
endfunction
1414

15+
" coc or LCN
16+
function! s:dispatch(...) abort
17+
if a:0 == 2
18+
let cmd = s:coc ?
19+
\ printf('call CocAction("%s")', a:1) :
20+
\ printf('call LanguageClient#%s()', a:2)
21+
execute cmd
22+
endif
23+
endfunction
24+
1525
" ================================================
1626
" LSP
1727
" ================================================
1828
function! spacevim#lang#util#FindReferences() abort
19-
if s:coc
20-
call CocAction('jumpReferences')
21-
return
22-
endif
23-
24-
call LanguageClient#textDocument_references()
29+
call s:dispatch('jumpReferences', 'textDocument_references')
2530
endfunction
2631

2732
function! spacevim#lang#util#Rename() abort
28-
if s:coc
29-
call CocAction('rename')
30-
return
31-
endif
33+
call s:dispatch('rename', 'textDocument_rename')
34+
endfunction
35+
36+
function! spacevim#lang#util#DocumentSymbol() abort
37+
call s:dispatch('documentSymbols', 'textDocument_documentSymbol')
38+
endfunction
3239

33-
call LanguageClient#textDocument_rename()
40+
function! spacevim#lang#util#WorkspaceSymbol() abort
41+
call s:dispatch('workspaceSymbols', 'workspace_symbol')
3442
endfunction
3543

3644
function! spacevim#lang#util#Format() abort
@@ -45,20 +53,6 @@ function! spacevim#lang#util#Format() abort
4553
endif
4654
endfunction
4755

48-
function! spacevim#lang#util#DocumentSymbol() abort
49-
if s:coc
50-
call CocAction('documentSymbols')
51-
endif
52-
call LanguageClient#textDocument_documentSymbol()
53-
endfunction
54-
55-
function! spacevim#lang#util#WorkspaceSymbol() abort
56-
if s:coc
57-
call CocAction('workspaceSymbols')
58-
endif
59-
call LanguageClient#workspace_symbol()
60-
endfunction
61-
6256
function! spacevim#lang#util#CodeAction() abort
6357
if s:coc
6458
call CocAction('codeAction', '')
@@ -110,15 +104,9 @@ function! spacevim#lang#util#Definition() abort
110104
endfunction
111105

112106
function! spacevim#lang#util#TypeDefinition() abort
113-
if s:coc
114-
call CocAction('jumpTypeDefinition')
115-
return
116-
endif
107+
call s:dispatch('jumpTypeDefinition', 'textDocument_typeDefinition')
117108
endfunction
118109

119110
function! spacevim#lang#util#Implementation() abort
120-
if s:coc
121-
call CocAction('jumpImplementation')
122-
return
123-
endif
111+
call s:dispatch('jumpImplementation', 'textDocument_implementation')
124112
endfunction

0 commit comments

Comments
 (0)