language/bash: migrate to vim.lsp.servers

This commit is contained in:
Ching Pei Yang 2025-04-05 23:41:28 +02:00
parent 940f78fcb4
commit 583f436e6e
No known key found for this signature in database
GPG key ID: B3841364253DC4C8

View file

@ -5,31 +5,28 @@
... ...
}: let }: let
inherit (builtins) attrNames; inherit (builtins) attrNames;
inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList; inherit (lib.types) enum package listOf bool;
inherit (lib.types) enum either package listOf str bool; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.types) diagnostics mkGrammarOption; inherit (lib.nvim.types) diagnostics mkGrammarOption;
inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.bash; cfg = config.vim.languages.bash;
defaultServer = "bash-ls"; defaultServer = "bash-ls";
servers = { servers = {
bash-ls = { bash-ls.options = {
package = pkgs.bash-language-server; cmd = [(getExe pkgs.bash-language-server) "start"];
lspConfig = '' settings = {
lspconfig.bashls.setup{ bashIde = {
capabilities = capabilities; globPattern =
on_attach = default_on_attach; mkLuaInline "vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)'";
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}''
}; };
} };
''; filetypes = ["sh" "bash"];
root_markers = [".git"];
}; };
}; };
@ -60,15 +57,8 @@ in {
server = mkOption { server = mkOption {
description = "Bash LSP server to use"; description = "Bash LSP server to use";
type = enum (attrNames servers); type = listOf (enum (attrNames servers));
default = defaultServer; default = [defaultServer];
};
package = mkOption {
description = "bash-language-server package, or the command to run as a list of strings";
example = literalExpression ''[lib.getExe pkgs.nodePackages.bash-language-server "start"]'';
type = either package (listOf str);
default = pkgs.bash-language-server;
}; };
}; };
@ -108,8 +98,12 @@ in {
}) })
(mkIf cfg.lsp.enable { (mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true; vim.lsp.servers =
vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig; mapListToAttrs (name: {
inherit name;
value = servers.${name}.options;
})
cfg.lsp.server;
}) })
(mkIf cfg.format.enable { (mkIf cfg.format.enable {