nvim: update lsp config

This commit is contained in:
Kevin Baensch 2024-12-14 21:44:39 +01:00
parent 5e0a29628d
commit 9faaef80fa
Signed by: derped
GPG key ID: C0F1D326C7626543
2 changed files with 33 additions and 35 deletions

View file

@ -18,29 +18,18 @@ lib.mkIf (lib.elem "nvim::cmp" config.machine.pkgs) {
config = # lua config = # lua
'' ''
function() 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 = require('cmp')
local cmp_action = lsp_zero.cmp_action()
cmp.setup({ cmp.setup({
${ ${
lib.optionalString (lib.elem "nvim::lsp" config.machine.pkgs) # lua lib.optionalString (lib.elem "nvim::lsp" config.machine.pkgs) # lua
''formatting = lsp_zero.cmp_format(),'' ''sources = { { name = 'nvim_lsp' }, },''
} }
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({ select = true }), ['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-u>'] = cmp.mapping.scroll_docs(-4), ['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4), ['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-f>'] = cmp_action.luasnip_jump_forward(),
['<C-b>'] = cmp_action.luasnip_jump_backward(),
}) })
}) })
end end

View file

@ -25,21 +25,6 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
dir = vPlug: vPlug.SchemaStore-nvim; 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; dir = vPlug: vPlug.cmp-nvim-lsp;
lazy = true; lazy = true;
@ -62,6 +47,10 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
init = # lua init = # lua
'' ''
function() 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 ---Force a specific language for ltex-ls
---@param lang string ---@param lang string
function SetLtexLang(lang) function SetLtexLang(lang)
@ -81,15 +70,35 @@ lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
config = # lua config = # lua
'' ''
function() function()
-- This is where all the LSP shenanigans will live local lsp_defaults = require('lspconfig').util.default_config
local lsp_zero = require('lsp-zero')
lsp_zero.extend_lspconfig()
lsp_zero.on_attach(function(client, bufnr) -- Add cmp_nvim_lsp capabilities settings to lspconfig
-- see :help lsp-zero-keybindings -- This should be executed before you configure any language server
-- to learn the available actions lsp_defaults.capabilities = vim.tbl_deep_extend(
lsp_zero.default_keymaps({buffer = bufnr}) 'force',
end) 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', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
vim.keymap.set({'n', 'x'}, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
end,
})
-- (Optional) Configure lua language server for neovim -- (Optional) Configure lua language server for neovim
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')