2023-02-01 20:11:37 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2023-04-17 22:27:27 +02:00
|
|
|
pkgs,
|
2023-02-01 20:11:37 +01:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
with builtins; let
|
|
|
|
cfg = config.vim.lsp;
|
2023-04-17 22:27:27 +02:00
|
|
|
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
|
2023-02-01 20:11:37 +01:00
|
|
|
in {
|
2023-04-17 22:27:27 +02:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
vim.startPlugins = optional usingNvimCmp "cmp-nvim-lsp";
|
|
|
|
|
2023-04-18 01:34:41 +02:00
|
|
|
vim.autocomplete.sources = {"nvim_lsp" = "[LSP]";};
|
2023-04-17 22:27:27 +02:00
|
|
|
|
|
|
|
vim.luaConfigRC.lsp-setup = ''
|
|
|
|
vim.g.formatsave = ${boolToString cfg.formatOnSave};
|
|
|
|
|
|
|
|
local attach_keymaps = function(client, bufnr)
|
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lgD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lgd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lgt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lgn', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lgp', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lwa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lwr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lwl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lh', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ln', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Enable formatting
|
|
|
|
format_callback = function(client, bufnr)
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
|
|
group = augroup,
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = function()
|
|
|
|
if vim.g.formatsave then
|
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
|
|
local params = require'vim.lsp.util'.make_formatting_params({})
|
|
|
|
client.request('textDocument/formatting', params, nil, bufnr)
|
2023-02-01 20:11:37 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-04-17 22:27:27 +02:00
|
|
|
})
|
|
|
|
end
|
2023-02-01 20:11:37 +01:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
default_on_attach = function(client, bufnr)
|
|
|
|
attach_keymaps(client, bufnr)
|
|
|
|
format_callback(client, bufnr)
|
|
|
|
end
|
2023-02-01 20:11:37 +01:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"}
|
|
|
|
'';
|
|
|
|
};
|
2023-02-01 20:11:37 +01:00
|
|
|
}
|