]> src.twobees.de Git - dotfiles.git/blob - stow/nvim/.config/nvim/after/plugin/lspsetup.lua
../..
[dotfiles.git] / stow / nvim / .config / nvim / after / plugin / lspsetup.lua
1 local lsp = require('lsp-zero')
2
3 lsp.preset('recommended')
4 lsp.configure('sumneko_lua', {
5     settings = {
6         Lua = {
7             diagnostics = {
8                 globals = { 'vim' }
9             }
10         }
11     }
12 })
13
14 lsp.on_attach = function (_, bufnr)
15     local options = { buffer = bufnr, remap = false }
16     vim.keymap.set ("n", "K", vim.lsp.buf.hover, options) -- buffer=0 -> only in current buffer
17     vim.keymap.set ("n", "gd", vim.lsp.buf.definition, options) -- goto definition
18     vim.keymap.set ("n", "gT", vim.lsp.buf.type_definition, options) -- goto typedefinition
19     vim.keymap.set ("n", "gi", vim.lsp.buf.implementation, options) -- goto implementation
20     vim.keymap.set ("n", "dj", vim.diagnostic.goto_next, options) -- goto dignostic next
21     vim.keymap.set ("n", "dk", vim.diagnostic.goto_prev, options) -- goto diognostic prev
22     vim.keymap.set ("n", "dl", "<cmd>Telescope diagnostic", options) -- goto list failure
23     vim.keymap.set ("n", "<leader>r", vim.lsp.buf.rename, options)
24     vim.keymap.set ("n", "<leader>f", vim.lsp.buf.code_action, options)
25 end
26
27 local cmp = require('cmp')
28 local cmp_select = {behavior = cmp.SelectBehavior.Select}
29 local cmp_mappings = lsp.defaults.cmp_mappings({
30     ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
31     ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
32     ['<C-y>'] = cmp.mapping.confirm({ select = true }),
33     ["<C-Space>"] = cmp.mapping.complete(),
34 })
35
36 lsp.setup_nvim_cmp({
37     mapping = cmp_mappings,
38 })
39
40 cmp.setup({
41     experimental = { ghost_text = true },
42 });
43
44 lsp.setup()
45
46 vim.diagnostic.config( { virtual_text = true } )