convert ruby module

This commit is contained in:
sjcobb 2025-07-11 14:01:35 +01:00
commit d0e8de0951

View file

@ -9,44 +9,41 @@
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.types) mkGrammarOption diagnostics;
inherit (lib.nvim.lua) expToLua;
inherit (lib.lists) isList;
inherit (lib.types) either listOf package str enum;
inherit (lib.types) listOf package enum;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.ruby;
defaultServer = "rubyserver";
defaultServers = ["solargraph"];
servers = {
rubyserver = {
package = pkgs.rubyPackages.solargraph;
lspConfig = ''
lspconfig.solargraph.setup {
capabilities = capabilities,
on_attach = attach_keymaps,
flags = {
debounce_text_changes = 150,
},
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/solargraph", "stdio" }''
}
}
'';
ruby_lsp = {
enable = true;
cmd = [(getExe pkgs.ruby-lsp)];
filetypes = ["ruby" "eruby"];
root_markers = ["Gemfile" ".git"];
init_options = {
formatter = "auto";
};
};
solargraph = {
enable = true;
cmd = [(getExe pkgs.rubyPackages.solargraph) "stdio"];
filetypes = ["ruby"];
root_markers = ["Gemfile" ".git"];
settings = {
solargraph = {
diagnostics = true;
};
};
flags = {
debounce_text_changes = 150;
};
init_options = {
formatting = true;
};
rubylsp = {
package = pkgs.ruby-lsp;
lspConfig = ''
lspconfig.ruby_lsp.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/ruby-lsp" }''
}
}
'';
};
};
@ -79,17 +76,11 @@ in {
lsp = {
enable = mkEnableOption "Ruby LSP support" // {default = config.vim.lsp.enable;};
server = mkOption {
type = enum (attrNames servers);
default = defaultServer;
servers = mkOption {
type = listOf (enum (attrNames servers)); default = defaultServers;
default = defaultServers;
description = "Ruby LSP server to use";
};
package = mkOption {
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
description = "Ruby LSP server package, or the command to run as a list of strings";
};
};
format = {
@ -128,8 +119,12 @@ in {
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.ruby-lsp = servers.${cfg.lsp.server}.lspConfig;
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
})
(mkIf cfg.format.enable {