vim/dot-vim/lsp.vim 2.5 K raw
1
" Enable diagnostics highlighting
2
let lspOpts = #{autoHighlightDiags: v:true}
3
autocmd User LspSetup call LspOptionsSet(lspOpts)
4
let lspServers = [
5
      \ #{
6
      \   name: 'rust-analyzer',
7
      \   filetype: ['rust'],
8
      \   path: 'rust-analyzer',
9
      \   args: []
10
      \ },
11
      \ #{
12
      \   name: 'lua-language-server',
13
      \   filetype: ['lua'],
14
      \   path: 'lua-language-server',
15
      \   args: [],
16
      \   rootSearch: ['.luarc.json', '.luarc.jsonc', '.luacheckrc',
17
      \                'stylua.toml', '.stylua.toml', 'selene.toml',
18
      \                'selene.yml', '.git'],
19
      \   workspaceConfig: #{
20
      \     Lua: #{
21
      \       diagnostics: #{ globals: ['vim'] }
22
      \     }
23
      \   }
24
      \ },
25
      \ #{
26
      \   name: 'tsserver',
27
      \   filetype: ['typescript', 'typescriptreact', 'typescript.tsx',
28
      \               'javascript', 'javascriptreact', 'javascript.jsx'],
29
      \   path: 'vtsls',
30
      \   args: ['--stdio'],
31
      \   rootSearch: ['tsconfig.json', 'jsconfig.json', 'package.json', '.git']
32
      \ },
33
      \ #{
34
      \   name: 'gopls',
35
      \   filetype: ['go', 'gomod', 'gowork',
36
      \               'gotmpl', 'gosum'],
37
      \   path: 'gopls',
38
      \   args: [],
39
      \   rootSearch: ['go.mod', 'go.work', '.git']
40
      \ },
41
      \ #{
42
      \   name: 'html',
43
      \   filetype: ['html'],
44
      \   path: 'vscode-html-language-server',
45
      \   args: ['--stdio'],
46
      \   rootSearch: ['index.html', 'package.json', '.git']
47
      \ },
48
      \ #{
49
      \   name: 'astro',
50
      \   filetype: ['astro'],
51
      \   path: 'astro-ls',
52
      \   args: ['--stdio'],
53
      \   rootSearch: ['package.json', 'tsconfig.json', 'jsconfig.json', '.git'],
54
      \   initializationOptions: #{
55
      \     typescript: #{
56
      \       tsdk: expand('~/.bun/install/global/node_modules/typescript/lib')
57
      \     }
58
      \   }
59
      \ }
60
      \ ]
61
62
autocmd User LspSetup call LspAddServer(lspServers)
63
64
" Key mappings
65
nnoremap gd :LspGotoDefinition<CR>
66
nnoremap gr :LspShowReferences<CR>
67
nnoremap K  :LspHover<CR>
68
nnoremap gl :LspDiag current<CR>
69
nnoremap <leader>nd :LspDiag next \| LspDiag current<CR>
70
nnoremap <leader>pd :LspDiag prev \| LspDiag current<CR>
71
inoremap <silent> <C-Space> <C-x><C-o>
72
73
" Set omnifunc for completion
74
autocmd FileType rust setlocal omnifunc=lsp#complete
75
76
" Custom diagnostic sign characters
77
autocmd User LspSetup call LspOptionsSet(#{
78
    \   diagSignErrorText: '✘',
79
    \   diagSignWarningText: '▲',
80
    \   diagSignInfoText: '»',
81
    \   diagSignHintText: '⚑',
82
    \ })