dotfiles/modules/common/neovim/config/lsp.nix

67 lines
2.6 KiB
Nix
Raw Normal View History

2022-11-28 02:11:41 +00:00
{ pkgs, dsl, ... }: {
plugins = [
pkgs.vimPlugins.nvim-lspconfig
pkgs.vimPlugins.lsp-colors-nvim
pkgs.vimPlugins.null-ls-nvim
];
use.lspconfig.lua_ls.setup = dsl.callWith {
2022-11-28 02:11:41 +00:00
settings = { Lua = { diagnostics = { globals = [ "vim" "hs" ]; }; }; };
capabilities = dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
cmd = [ "${pkgs.lua-language-server}/bin/lua-language-server" ];
2022-11-28 02:11:41 +00:00
};
use.lspconfig.nil_ls.setup = dsl.callWith {
cmd = [ "${pkgs.nil}/bin/nil" ];
capabilities = dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
};
use.lspconfig.pyright.setup = dsl.callWith {
cmd = [ "${pkgs.pyright}/bin/pyright-langserver" "--stdio" ];
};
use.lspconfig.terraformls.setup =
2022-11-30 17:56:30 +00:00
dsl.callWith { cmd = [ "${pkgs.terraform-ls}/bin/terraform-ls" "serve" ]; };
2022-11-28 02:11:41 +00:00
vim.api.nvim_create_augroup = dsl.callWith [ "LspFormatting" { } ];
lua = ''
2022-11-29 05:36:30 +00:00
${builtins.readFile ./lsp.lua}
2022-11-28 02:11:41 +00:00
require("null-ls").setup({
sources = {
2022-11-29 05:36:30 +00:00
require("null-ls").builtins.formatting.stylua.with({ command = "${pkgs.stylua}/bin/stylua" }),
require("null-ls").builtins.formatting.black.with({ command = "${pkgs.black}/bin/black" }),
2023-04-19 20:50:05 +00:00
require("null-ls").builtins.diagnostics.ruff.with({ command = "${pkgs.ruff}/bin/ruff" }),
2022-11-29 05:36:30 +00:00
require("null-ls").builtins.formatting.fish_indent.with({ command = "${pkgs.fish}/bin/fish_indent" }),
require("null-ls").builtins.formatting.nixfmt.with({ command = "${pkgs.nixfmt}/bin/nixfmt" }),
require("null-ls").builtins.formatting.rustfmt.with({ command = "${pkgs.rustfmt}/bin/rustfmt" }),
require("null-ls").builtins.diagnostics.shellcheck.with({ command = "${pkgs.shellcheck}/bin/shellcheck" }),
require("null-ls").builtins.formatting.shfmt.with({
2022-11-28 02:11:41 +00:00
command = "${pkgs.shfmt}/bin/shfmt",
2022-11-29 05:36:30 +00:00
extra_args = { "-i", "4", "-ci" },
2022-11-28 02:11:41 +00:00
}),
require("null-ls").builtins.formatting.terraform_fmt.with({
command = "${pkgs.terraform}/bin/terraform",
extra_filetypes = { "hcl" },
}),
2022-11-28 02:11:41 +00:00
},
on_attach = function(client, bufnr)
2022-11-29 05:36:30 +00:00
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,
2022-11-28 02:11:41 +00:00
})
'';
}