Made cmd argument of nil_ls a list

This commit is contained in:
Liyua 2025-07-01 20:28:04 +02:00
commit 951634e0f7
No known key found for this signature in database
GPG key ID: AFF37010586DE14D

View file

@ -4,8 +4,7 @@
lib, lib,
inputs, inputs,
... ...
}: }: let
let
inherit (builtins) attrNames; inherit (builtins) attrNames;
inherit (lib) concatStringsSep mkLuaInline; inherit (lib) concatStringsSep mkLuaInline;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
@ -13,7 +12,8 @@ let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList; inherit (lib.lists) isList;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.types) inherit
(lib.types)
anything anything
attrsOf attrsOf
enum enum
@ -32,32 +32,37 @@ let
noFormat = "on_attach = attach_keymaps"; noFormat = "on_attach = attach_keymaps";
defaultServer = "nil"; defaultServer = "nil";
packageToCmd = packageToCmd = package: defaultCmd:
package: defaultCmd: if isList package
if isList package then expToLua package else ''{"${package}/bin/${defaultCmd}"}''; then expToLua package
else ''{"${package}/bin/${defaultCmd}"}'';
servers = { servers = {
nil = { nil = {
package = inputs.nil.packages.${pkgs.stdenv.system}.nil; package = inputs.nil.packages.${pkgs.stdenv.system}.nil;
internalFormatter = true; internalFormatter = true;
lspConfig = ''lspconfig.nil_ls.setup ${ lspConfig = ''lspconfig.nil_ls.setup ${
toLuaObject { toLuaObject {
capabilities = mkLuaInline "capabilities"; capabilities = mkLuaInline "capabilities";
on_attach = if cfg.format.enable then mkLuaInline "default_on_attach" else "attach_keymaps"; on_attach =
cmd = packageToCmd cfg.lsp.package "nil"; if cfg.format.enable
settings.nil = { then mkLuaInline "default_on_attach"
formatting.command = else "attach_keymaps";
if cfg.format.enable then cmd = [(packageToCmd cfg.lsp.package "nil")];
if cfg.format.type == "alejandra" then settings.nil =
''{"${cfg.format.package}/bin/alejandra", "--quiet"}'' {
else if cfg.format.type == "nixfmt" then formatting.command =
''{"${cfg.format.package}/bin/nixfmt"}'' if cfg.format.enable
else then
null if cfg.format.type == "alejandra"
else then ''{"${cfg.format.package}/bin/alejandra", "--quiet"}''
null; else if cfg.format.type == "nixfmt"
} // cfg.lsp.options; then ''{"${cfg.format.package}/bin/nixfmt"}''
} else null
}''; else null;
}
// cfg.lsp.options;
}
}'';
# lspConfig = '' # lspConfig = ''
# lspconfig.nil_ls.setup{ # lspconfig.nil_ls.setup{
# capabilities = capabilities, # capabilities = capabilities,
@ -94,7 +99,11 @@ let
lspConfig = '' lspConfig = ''
lspconfig.nixd.setup{ lspconfig.nixd.setup{
capabilities = capabilities, capabilities = capabilities,
${if cfg.format.enable then useFormat else noFormat}, ${
if cfg.format.enable
then useFormat
else noFormat
},
cmd = ${packageToCmd cfg.lsp.package "nixd"}, cmd = ${packageToCmd cfg.lsp.package "nixd"},
${optionalString cfg.format.enable '' ${optionalString cfg.format.enable ''
settings = { settings = {
@ -158,22 +167,25 @@ let
''; '';
}; };
}; };
in in {
{
options.vim.languages.nix = { options.vim.languages.nix = {
enable = mkEnableOption "Nix language support"; enable = mkEnableOption "Nix language support";
treesitter = { treesitter = {
enable = mkEnableOption "Nix treesitter" // { enable =
default = config.vim.languages.enableTreesitter; mkEnableOption "Nix treesitter"
}; // {
default = config.vim.languages.enableTreesitter;
};
package = mkGrammarOption pkgs "nix"; package = mkGrammarOption pkgs "nix";
}; };
lsp = { lsp = {
enable = mkEnableOption "Nix LSP support" // { enable =
default = config.vim.lsp.enable; mkEnableOption "Nix LSP support"
}; // {
default = config.vim.lsp.enable;
};
server = mkOption { server = mkOption {
description = "Nix LSP server to use"; description = "Nix LSP server to use";
type = enum (attrNames servers); type = enum (attrNames servers);
@ -195,9 +207,11 @@ in
}; };
format = { format = {
enable = mkEnableOption "Nix formatting" // { enable =
default = config.vim.languages.enableFormat; mkEnableOption "Nix formatting"
}; // {
default = config.vim.languages.enableFormat;
};
type = mkOption { type = mkOption {
description = "Nix formatter to use"; description = "Nix formatter to use";
@ -213,9 +227,11 @@ in
}; };
extraDiagnostics = { extraDiagnostics = {
enable = mkEnableOption "extra Nix diagnostics" // { enable =
default = config.vim.languages.enableExtraDiagnostics; mkEnableOption "extra Nix diagnostics"
}; // {
default = config.vim.languages.enableExtraDiagnostics;
};
types = diagnostics { types = diagnostics {
langDesc = "Nix"; langDesc = "Nix";
@ -247,7 +263,7 @@ in
(mkIf cfg.treesitter.enable { (mkIf cfg.treesitter.enable {
vim.treesitter.enable = true; vim.treesitter.enable = true;
vim.treesitter.grammars = [ cfg.treesitter.package ]; vim.treesitter.grammars = [cfg.treesitter.package];
}) })
(mkIf cfg.lsp.enable { (mkIf cfg.lsp.enable {
@ -258,7 +274,7 @@ in
(mkIf (cfg.format.enable && (!cfg.lsp.enable || !servers.${cfg.lsp.server}.internalFormatter)) { (mkIf (cfg.format.enable && (!cfg.lsp.enable || !servers.${cfg.lsp.server}.internalFormatter)) {
vim.formatter.conform-nvim = { vim.formatter.conform-nvim = {
enable = true; enable = true;
setupOpts.formatters_by_ft.nix = [ cfg.format.type ]; setupOpts.formatters_by_ft.nix = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = { setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package; command = getExe cfg.format.package;
}; };
@ -272,7 +288,8 @@ in
linters = mkMerge ( linters = mkMerge (
map (name: { map (name: {
${name}.cmd = getExe diagnosticsProviders.${name}.package; ${name}.cmd = getExe diagnosticsProviders.${name}.package;
}) cfg.extraDiagnostics.types })
cfg.extraDiagnostics.types
); );
}; };
}) })