From 9faaef80fadd81da2d84430af3ec1df71b3697ab Mon Sep 17 00:00:00 2001 From: derped Date: Sat, 14 Dec 2024 21:44:39 +0100 Subject: [PATCH] nvim: update lsp config --- pkgsets/nvim/cmp.nix | 13 +---------- pkgsets/nvim/lsp.nix | 55 ++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/pkgsets/nvim/cmp.nix b/pkgsets/nvim/cmp.nix index d79f8d4..b16e67a 100644 --- a/pkgsets/nvim/cmp.nix +++ b/pkgsets/nvim/cmp.nix @@ -18,29 +18,18 @@ lib.mkIf (lib.elem "nvim::cmp" config.machine.pkgs) { config = # lua '' function() - ${ - lib.optionalString (lib.elem "nvim::lsp" config.machine.pkgs) # lua - '' - local lsp_zero = require('lsp-zero') - lsp_zero.extend_cmp() - '' - } - local cmp = require('cmp') - local cmp_action = lsp_zero.cmp_action() cmp.setup({ ${ lib.optionalString (lib.elem "nvim::lsp" config.machine.pkgs) # lua - ''formatting = lsp_zero.cmp_format(),'' + ''sources = { { name = 'nvim_lsp' }, },'' } mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.complete(), [''] = cmp.mapping.confirm({ select = true }), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - [''] = cmp_action.luasnip_jump_forward(), - [''] = cmp_action.luasnip_jump_backward(), }) }) end diff --git a/pkgsets/nvim/lsp.nix b/pkgsets/nvim/lsp.nix index b5b6bb8..07aa715 100644 --- a/pkgsets/nvim/lsp.nix +++ b/pkgsets/nvim/lsp.nix @@ -25,21 +25,6 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) { dir = vPlug: vPlug.SchemaStore-nvim; } - { - dir = vPlug: vPlug.lsp-zero-nvim; - lazy = true; - # TODO: This is a bit of a workaround... - config = "false"; - init = # lua - '' - function() - -- Disable automatic setup, we are doing it manually - vim.g.lsp_zero_extend_cmp = 0 - vim.g.lsp_zero_extend_lspconfig = 0 - end - ''; - } - { dir = vPlug: vPlug.cmp-nvim-lsp; lazy = true; @@ -62,6 +47,10 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) { init = # lua '' function() + -- Reserve a space in the gutter + -- This will avoid an annoying layout shift in the screen + vim.opt.signcolumn = 'yes' + ---Force a specific language for ltex-ls ---@param lang string function SetLtexLang(lang) @@ -81,15 +70,35 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) { config = # lua '' function() - -- This is where all the LSP shenanigans will live - local lsp_zero = require('lsp-zero') - lsp_zero.extend_lspconfig() + local lsp_defaults = require('lspconfig').util.default_config - lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({buffer = bufnr}) - end) + -- Add cmp_nvim_lsp capabilities settings to lspconfig + -- This should be executed before you configure any language server + lsp_defaults.capabilities = vim.tbl_deep_extend( + 'force', + lsp_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() + ) + + -- LspAttach is where you enable features that only work + -- if there is a language server active in the file + vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = {buffer = event.buf} + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, + }) -- (Optional) Configure lua language server for neovim local lspconfig = require('lspconfig')