]> git.r.bdr.sh - rbdr/dotfiles/blob - config/nvim/lua/lsp.lua
Start replacing CoC with neovim's LSP support
[rbdr/dotfiles] / config / nvim / lua / lsp.lua
1 local lspconfig = require('lspconfig')
2 local capabilities = vim.lsp.protocol.make_client_capabilities()
3 capabilities.textDocument.completion.completionItem.snippetSupport = true
4
5 lspconfig.tsserver.setup {}
6 lspconfig.eslint.setup{}
7 lspconfig.svelte.setup{}
8 lspconfig.pyright.setup {}
9 lspconfig.dartls.setup{}
10 lspconfig.rust_analyzer.setup {
11 -- Server-specific settings. See `:help lspconfig-setup`
12 settings = {
13 ['rust-analyzer'] = {},
14 },
15 }
16 lspconfig.cssls.setup {
17 capabilities = capabilities,
18 }
19 lspconfig.html.setup {
20 capabilities = capabilities,
21 }
22 lspconfig.lua_ls.setup{}
23
24 -- Global mappings.
25 -- See `:help vim.diagnostic.*` for documentation on any of the below functions
26 vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
27 vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
28 vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
29 vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
30
31 -- Use LspAttach autocommand to only map the following keys
32 -- after the language server attaches to the current buffer
33 vim.api.nvim_create_autocmd('LspAttach', {
34 group = vim.api.nvim_create_augroup('UserLspConfig', {}),
35 callback = function(ev)
36 -- Enable completion triggered by <c-x><c-o>
37 vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
38
39 -- Buffer local mappings.
40 -- See `:help vim.lsp.*` for documentation on any of the below functions
41 local opts = { buffer = ev.buf }
42 vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
43 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
44 vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
45 vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
46 vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
47 vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
48 vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
49 vim.keymap.set('n', '<space>wl', function()
50 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
51 end, opts)
52 vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
53 vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
54 vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
55 vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
56 vim.keymap.set('n', '<space>f', function()
57 vim.lsp.buf.format { async = true }
58 end, opts)
59 end,
60 })