convert lua module

This commit is contained in:
sjcobb 2025-07-02 00:15:21 +01:00
commit 1f3b417469

View file

@ -8,32 +8,13 @@
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.types) bool enum listOf package;
inherit (lib.lists) isList;
inherit (lib.types) bool either enum listOf package str;
inherit (lib.nvim.types) diagnostics mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryBefore;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.lua;
defaultServers = ["lua-language-server"];
servers = {
lua-language-server = {
enable = true;
cmd = [(getExe pkgs.lua-language-server)];
filetypes = ["lua"];
root_markers = [
".luarc.json"
".luarc.jsonc"
".luacheckrc"
".stylua.toml"
"stylua.toml"
"selene.toml"
"selene.yml"
".git"
];
};
};
defaultFormat = "stylua";
formats = {
stylua = {
@ -62,11 +43,12 @@ in {
};
lsp = {
enable = mkEnableOption "Lua LSP support" // {default = config.vim.lsp.enable;};
servers = mkOption {
description = "Lua LSP server to use";
type = listOf (enum (attrNames servers));
default = defaultServers;
enable = mkEnableOption "Lua LSP support via LuaLS" // {default = config.vim.lsp.enable;};
package = mkOption {
description = "LuaLS package, or the command to run as a list of strings";
type = either package (listOf str);
default = pkgs.lua-language-server;
};
lazydev.enable = mkEnableOption "lazydev.nvim integration, useful for neovim plugin developers";
@ -109,17 +91,23 @@ in {
(mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.lua-lsp = ''
lspconfig.lua_ls.setup {
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${getExe cfg.lsp.package}"}''
};
}
'';
})
(mkIf cfg.lsp.lazydev.enable {
vim.startPlugins = ["lazydev-nvim"];
vim.pluginRC.lazydev = entryBefore ["lsp-servers"] ''
vim.pluginRC.lazydev = entryBefore ["lua-lsp"] ''
require("lazydev").setup({
enabled = function(root_dir)
return not vim.uv.fs_stat(root_dir .. "/.luarc.json")