aboutsummaryrefslogtreecommitdiff
path: root/.vim/after/plugin/lsp.vim
blob: 4bc1a0f29d99ba536d672ea3b9465e515ecf50a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if has('nvim')
    finish
endif

let g:lsp_diagnostics_enabled = 0
let g:lsp_document_code_action_signs_enabled = 0
let g:lsp_use_native_client = 1

packadd vim-lsp
packadd vim-lsp-snippets
packadd vim-lsp-ultisnips

" This package will help enable diagnostic config of vim-lsp and then it
" can help send the result to ALE. Pay attention of the loading order.
packadd vim-lsp-ale

if executable('pylsp')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pylsp',
        \ 'cmd': {server_info->['pylsp']},
        \ 'allowlist': ['python'],
        \ })
endif

if executable('gopls')
    au User lsp_setup call lsp#register_server({
          \ 'name': 'gopls',
          \ 'cmd': {server_info->['gopls']},
          \ 'allowlist': ['go'],
          \ })
endif

if executable('clangd')
    au User lsp_setup call lsp#register_server({
                \ 'name': 'clangd',
                \ 'cmd': {server_info->['clangd']},
                \ 'allowlist': ['c', 'cpp'],
                \ })
endif

if executable('omnisharp')
    au User lsp_setup call lsp#register_server({
                \ 'name': 'omnisharp',
                \ 'cmd': {server_info->['omnisharp', '-lsp']},
                \ 'allowlist': ['cs'],
                \ })
endif

if executable('godot')
    au User lsp_setup
        \ call lsp#register_server({
            \ 'name': 'godot',
            \ 'tcp': {server_info->'localhost:6008'},
            \ 'allowlist': ['gdscript', 'gdscript3']
        \ })
endif

" https://github.com/mickael-menu/zk
if executable('zk')
    au User lsp_setup call lsp#register_server({
                \ 'name': 'zk',
                \ 'cmd': {server_info->['zk', 'lsp']},
                \ 'allowlist': ['markdown'],
                \ })
endif

if executable('rust-analyzer')
    au User lsp_setup call lsp#register_server({
                \ 'name': 'rust-analyzer',
                \ 'cmd': {server_info->['rust-analyzer']},
                \ 'allowlist': ['rust'],
                \ })
endif

function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    setlocal nocscopetag
    if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> gs <plug>(lsp-document-symbol)
    nmap <buffer> gS <plug>(lsp-workspace-symbol)
    nmap <buffer> gr <plug>(lsp-references)
    nmap <buffer> gi <plug>(lsp-implementation)
    nmap <buffer> gy <plug>(lsp-type-definition)
    nmap <buffer> <leader>rn <plug>(lsp-rename)
    nmap <buffer> K <plug>(lsp-hover)

    let g:lsp_format_sync_timeout = 1000
    autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
endfunction

augroup lsp_install
    au!
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END