1
0
Fork 0
nixos/pkgsets/nvim/lsp.nix

123 lines
4.2 KiB
Nix

{
lib,
config,
pkgs,
fn,
...
}@inputs:
lib.mkIf (lib.elem "nvim::lsp" config.machine.pkgs) {
programs.nvim-lazy.lazyPlugins = [
# Yaml schema store for yamlls
{
lazy = true;
dir = vPlug: vPlug.SchemaStore-nvim;
}
# {
# dir = vPlug: vPlug.cmp-nvim-lsp;
# lazy = true;
# }
{
dir = vPlug: vPlug.nvim-lspconfig;
cmd = [ "LspInfo" ];
event = [
"BufReadPre"
"BufNewFile"
];
dependencies = (
vPlug: with vPlug; [
# cmp-nvim-lsp
blink-cmp
SchemaStore-nvim
# coq_nvim
]
);
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)
local clients = vim.lsp.get_clients({ buffer = 0 })
for _, client in ipairs(clients) do
if client.name == "ltex" then
vim.api.nvim_notify("Set ltex-ls lang to " .. lang, vim.log.levels.INFO, { title = "LTex Language", timeout = 2000, })
client.config.settings.ltex.language = lang
vim.lsp.buf_notify(0, "workspace/didChangeConfiguration", { settings = client.config.settings })
return
end
end
end
end
'';
opts = {
inlay_hints = {
enabled = true;
};
servers = lib.foldl (l: r: l // r) { } (
lib.map (path: import "${path}" (inputs // { inherit pkgs; })) (
fn.lst {
path = ((toString ./.) + "/lsp");
fullPath = true;
}
)
);
};
config = # lua
''
function(_, opts)
local lsp_defaults = require('lspconfig').util.default_config
-- 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,
})
local lspconfig = require('lspconfig')
for server, config in pairs(opts.servers) do
${lib.optionalString (lib.elem "nvim::blink" config.machine.pkgs) # lua
''
-- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
''
}
lspconfig[server].setup(config)
end
end
'';
}
];
}