nvim: update lsp config
This commit is contained in:
parent
5e0a29628d
commit
9faaef80fa
2 changed files with 33 additions and 35 deletions
|
@ -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({
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
['<C-u>'] = 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
|
||||
|
|
|
@ -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', '<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
|
||||
local lspconfig = require('lspconfig')
|
||||
|
|
Loading…
Reference in a new issue