nvf/modules/plugins/languages/bash/config.nix

84 lines
1.9 KiB
Nix
Raw Permalink Normal View History

2023-09-23 15:36:25 +00:00
{
pkgs,
config,
lib,
...
}: let
inherit (lib.lists) isList;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.lua) expToLua;
2024-03-24 00:14:39 +00:00
inherit (lib.nvim.languages) diagnosticsToLua;
2023-09-23 15:36:25 +00:00
cfg = config.vim.languages.bash;
2024-03-24 00:14:39 +00:00
diagnosticsProviders = {
2023-09-23 15:36:25 +00:00
shellcheck = {
package = pkgs.shellcheck;
nullConfig = pkg: ''
table.insert(
ls_sources,
null_ls.builtins.diagnostics.shellcheck.with({
command = "${pkg}/bin/shellcheck",
})
)
'';
};
};
formats = {
shfmt = {
package = pkgs.shfmt;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.shfmt.with({
command = "${pkgs.shfmt}/bin/shfmt",
})
)
'';
};
};
servers = {
bash-ls = {
package = pkgs.nodePackages.bash-language-server;
lspConfig = ''
lspconfig.bashls.setup{
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
2023-09-23 15:36:25 +00:00
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}''
};
}
'';
};
};
in {
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.bash-format = formats.${cfg.format.type}.nullConfig;
})
(mkIf cfg.extraDiagnostics.enable {
vim.lsp.null-ls.enable = true;
2024-03-24 00:14:39 +00:00
vim.lsp.null-ls.sources = diagnosticsToLua {
2023-09-23 15:36:25 +00:00
lang = "bash";
config = cfg.extraDiagnostics.types;
2024-03-24 00:14:39 +00:00
inherit diagnosticsProviders;
2023-09-23 15:36:25 +00:00
};
})
]);
}