diff --git a/nvim/lua/autocompletion.lua b/nvim/lua/autocompletion.lua index d270caa..d41e526 100644 --- a/nvim/lua/autocompletion.lua +++ b/nvim/lua/autocompletion.lua @@ -27,14 +27,14 @@ cmp.setup({ }) }) --- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +-- Use buffer source for `/` cmp.setup.cmdline('/', { sources = { { name = 'buffer' } } }) --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +-- Use cmdline & path source for ':' cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } @@ -43,24 +43,28 @@ cmp.setup.cmdline(':', { }) }) --- Setup lspconfig. -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end -lspconfig = require "lspconfig" -lspconfig.tsserver.setup{ capabilities = capabilities } -lspconfig.intelephense.setup{ capabilities = capabilities } -lspconfig.vuels.setup{ capabilities = capabilities } -lspconfig.pylsp.setup{ capabilities = capabilities} -lspconfig.texlab.setup{ capabilities = capabilities } -lspconfig.gopls.setup { - cmd = {"gopls", "serve"}, - settings = { - gopls = { - analyses = { - unusedparams = true, - }, - staticcheck = true, - }, - }, - capabilities = capabilities -} + local opts = { noremap = true, silent = true } + buf_set_keymap("n", "gd", "Telescope lsp_definitions", opts) + buf_set_keymap("n", "gh", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gD", "Telescope lsp_implementations", opts) + buf_set_keymap("n", "gs", "lua vim.lsp.buf.signature_help()", opts) + buf_set_keymap("n", "gR", "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", "gH", "Telescope lsp_code_actions()", opts) + buf_set_keymap("n", "gr", "Telescope lsp_references", opts) + buf_set_keymap("n", "ge", "lua vim.diagnostic.open_float()", opts) +end + +local lsp_installer = require "nvim-lsp-installer" +lsp_installer.on_server_ready(function(server) + local opts = {} + opts.on_attach = on_attach + opts.capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + + server:setup(opts) + vim.cmd [[ do User LspAttachBuffers ]] +end) diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index d6a7f66..e7ee251 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -42,10 +42,6 @@ map {'n', 'e', ':NvimTreeToggle'} map {'n', '', 'Telescope buffers'} map {'n', 'f', 'Telescope find_files'} map {'n', 'l', 'Telescope live_grep'} -map {'n', ' gD', 'Telescope lsp_implementations'} -map {'n', ' gH', 'Telescope lsp_code_actions'} -map {'n', ' gd', 'Telescope lsp_definitions'} -map {'n', ' gr', 'Telescope lsp_references'} map {'n', ' gy', 'Telescope treesitter'} -- neo formatter @@ -57,8 +53,3 @@ map {'n', ' w', ':Goyo'} -- spelling map {'n', ' se', ':set spell spelllang=en'} map {'n', ' sd', ':set spell spelllang=de'} - -map {'n', ' gh', 'lua vim.lsp.buf.hover()'} -map {'n', ' gs', 'lua vim.lsp.buf.signature_help()'} -map {'n', ' gR', 'lua vim.lsp.buf.rename()'} -map {'n', ' ge', 'lua vim.diagnostic.open_float()'}