~yerinalexey/dotfiles

ref: 144a38b0aa0a39003633d53b77fe4e3ca29c054b dotfiles/nvim/lsp.vim -rw-r--r-- 2.4 KiB
144a38b0Alexey Yerin river,update-volume: fix old wob crashes 5 months ago
                                                                                
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
" Autocompletion and related settings

" Tab/Shift+Tab to cycle between completion options
" Enter to select if in completion mode, and insert a newline if not
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

" Force completion menu on Ctrl+space
imap <C-space> <Plug>(asyncomplete_force_refresh)

" Configure language servers
function! s:setup_lsp()
  if executable('gopls')
    " go get -u golang.org/x/tools/gopls
    " or
    " pacman -S gopls
    call lsp#register_server({
      \ 'name': 'gopls',
      \ 'cmd': {server_info->['gopls']},
      \ 'workspace_config': {
      \   'gopls': {
      \     'linkTarget': 'godocs.io'
      \   }
      \ },
      \ 'allowlist': ['go'],
      \ })
  endif

  if executable('rust-analyzer')
    " pacman -S rust-analyzer
    " or follow instructions on
    " https://rust-analyzer.github.io/manual.html#installation
    call lsp#register_server({
      \ 'name': 'rust-analyzer',
      \ 'cmd': {server_info->['rust-analyzer']},
      \ 'initialization_options': {
      \   'cargo': {
      \     'loadOutDirsFromCheck': v:true,
      \   },
      \   'procMacro': {
      \     'enable': v:true,
      \   },
      \ },
      \ 'allowlist': ['rust'],
      \ })
  endif

  " if executable('zls')
  "   " $ git clone https://github.com/zigtools/zls
  "   " $ zig build --prefix /usr/local install
  "   call lsp#register_server({
  "     \ 'name': 'zls',
  "     \ 'cmd': {server_info->['zls']},
  "     \ 'allowlist': ['zig'],
  "     \ })
  " endif
endfunction

" Runs on registered filetypes
function! s:lsp_enabled()
  setl omnifunc=lsp#complete

  if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif

  " LSP-specific bindings
  nmap <silent><buffer> K <Plug>(lsp-hover)
  nmap <silent><buffer> <leader>r <Plug>(lsp-rename)
  nmap <silent><buffer> <leader>c <Plug>(lsp-code-action)
  nmap <silent><buffer> <leader>gd <Plug>(lsp-defenition)
  nmap <silent><buffer> <leader>gi <Plug>(lsp-implementation)

  nmap <silent><buffer> <leader>[ <Plug>(lsp-previous-diagnostic)
  nmap <silent><buffer> <leader>] <Plug>(lsp-next-diagnostic)

  " 6 characters vs 17 characters
  command! Format :LspDocumentFormat
endfunction

augroup vim_lsp
  au!

  au User lsp_setup          :call <SID>setup_lsp()
  au User lsp_buffer_enabled :call <SID>lsp_enabled()
augroup END