modules/languages: finish making lib calls explicit

This commit is contained in:
raf 2024-03-09 08:49:22 +03:00
commit dfc7c6737f
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
16 changed files with 301 additions and 217 deletions

View file

@ -1,11 +1,15 @@
{
pkgs,
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.types) enum either listOf package str;
inherit (lib.nvim.lua) expToLua;
cfg = config.vim.languages.sql;
sqlfluffDefault = pkgs.sqlfluff;
@ -23,7 +27,7 @@
end,
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
then expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/sqls", "-config", string.format("%s/config.yml", vim.fn.getcwd()) }''
}
}
@ -68,7 +72,7 @@ in {
dialect = mkOption {
description = "SQL dialect for sqlfluff (if used)";
type = types.str;
type = str;
default = "ansi";
};
@ -77,7 +81,7 @@ in {
package = mkOption {
description = "SQL treesitter grammar to use";
type = types.package;
type = package;
default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.sql;
};
};
@ -87,14 +91,14 @@ in {
server = mkOption {
description = "SQL LSP server to use";
type = with types; enum (attrNames servers);
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
description = "SQL LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
@ -104,13 +108,13 @@ in {
type = mkOption {
description = "SQL formatter to use";
type = with types; enum (attrNames formats);
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "SQL formatter package";
type = types.package;
type = package;
default = formats.${cfg.format.type}.package;
};
};
@ -133,10 +137,14 @@ in {
})
(mkIf cfg.lsp.enable {
vim.startPlugins = ["sqls-nvim"];
vim = {
startPlugins = ["sqls-nvim"];
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.sql-lsp = servers.${cfg.lsp.server}.lspConfig;
lsp.lspconfig = {
enable = true;
sources.sql-lsp = servers.${cfg.lsp.server}.lspConfig;
};
};
})
(mkIf cfg.format.enable {