mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
Added workaround for nil configuration
This commit is contained in:
parent
5bad5dd94c
commit
3fa41b6d8b
1 changed files with 63 additions and 52 deletions
|
@ -4,7 +4,8 @@
|
|||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
}:
|
||||
let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib) concatStringsSep;
|
||||
inherit (lib.meta) getExe;
|
||||
|
@ -12,7 +13,16 @@
|
|||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.types) anything attrsOf enum either listOf nullOr package str;
|
||||
inherit (lib.types)
|
||||
anything
|
||||
attrsOf
|
||||
enum
|
||||
either
|
||||
listOf
|
||||
nullOr
|
||||
package
|
||||
str
|
||||
;
|
||||
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
||||
inherit (lib.nvim.lua) expToLua toLuaObject;
|
||||
|
||||
|
@ -22,10 +32,9 @@
|
|||
noFormat = "on_attach = attach_keymaps";
|
||||
|
||||
defaultServer = "nil";
|
||||
packageToCmd = package: defaultCmd:
|
||||
if isList package
|
||||
then expToLua package
|
||||
else ''{"${package}/bin/${defaultCmd}"}'';
|
||||
packageToCmd =
|
||||
package: defaultCmd:
|
||||
if isList package then expToLua package else ''{"${package}/bin/${defaultCmd}"}'';
|
||||
servers = {
|
||||
nil = {
|
||||
package = inputs.nil.packages.${pkgs.stdenv.system}.nil;
|
||||
|
@ -33,27 +42,22 @@
|
|||
lspConfig = ''
|
||||
lspconfig.nil_ls.setup{
|
||||
capabilities = capabilities,
|
||||
${
|
||||
if cfg.format.enable
|
||||
then useFormat
|
||||
else noFormat
|
||||
},
|
||||
${if cfg.format.enable then useFormat else noFormat},
|
||||
cmd = ${packageToCmd cfg.lsp.package "nil"},
|
||||
${optionalString cfg.format.enable ''
|
||||
settings = {
|
||||
["nil"] = {
|
||||
${optionalString (cfg.format.type == "alejandra")
|
||||
''
|
||||
${optionalString (cfg.format.type == "alejandra") ''
|
||||
formatting = {
|
||||
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
|
||||
},
|
||||
''}
|
||||
${optionalString (cfg.format.type == "nixfmt")
|
||||
''
|
||||
${optionalString (cfg.format.type == "nixfmt") ''
|
||||
formatting = {
|
||||
command = {"${cfg.format.package}/bin/nixfmt"},
|
||||
},
|
||||
''}
|
||||
nix = ${toLuaObject cfg.lsp.options},
|
||||
},
|
||||
},
|
||||
''}
|
||||
|
@ -67,28 +71,22 @@
|
|||
lspConfig = ''
|
||||
lspconfig.nixd.setup{
|
||||
capabilities = capabilities,
|
||||
${
|
||||
if cfg.format.enable
|
||||
then useFormat
|
||||
else noFormat
|
||||
},
|
||||
${if cfg.format.enable then useFormat else noFormat},
|
||||
cmd = ${packageToCmd cfg.lsp.package "nixd"},
|
||||
${optionalString cfg.format.enable ''
|
||||
settings = {
|
||||
nixd = {
|
||||
${optionalString (cfg.format.type == "alejandra")
|
||||
''
|
||||
${optionalString (cfg.format.type == "alejandra") ''
|
||||
formatting = {
|
||||
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
|
||||
},
|
||||
''}
|
||||
${optionalString (cfg.format.type == "nixfmt")
|
||||
''
|
||||
${optionalString (cfg.format.type == "nixfmt") ''
|
||||
formatting = {
|
||||
command = {"${cfg.format.package}/bin/nixfmt"},
|
||||
},
|
||||
''}
|
||||
options = ${toLuaObject cfg.lsp.options},
|
||||
nix = ${toLuaObject cfg.lsp.options},
|
||||
},
|
||||
},
|
||||
''}
|
||||
|
@ -108,7 +106,10 @@
|
|||
};
|
||||
};
|
||||
|
||||
defaultDiagnosticsProvider = ["statix" "deadnix"];
|
||||
defaultDiagnosticsProvider = [
|
||||
"statix"
|
||||
"deadnix"
|
||||
];
|
||||
diagnosticsProviders = {
|
||||
statix = {
|
||||
package = pkgs.statix;
|
||||
|
@ -134,17 +135,22 @@
|
|||
'';
|
||||
};
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.vim.languages.nix = {
|
||||
enable = mkEnableOption "Nix language support";
|
||||
|
||||
treesitter = {
|
||||
enable = mkEnableOption "Nix treesitter" // {default = config.vim.languages.enableTreesitter;};
|
||||
enable = mkEnableOption "Nix treesitter" // {
|
||||
default = config.vim.languages.enableTreesitter;
|
||||
};
|
||||
package = mkGrammarOption pkgs "nix";
|
||||
};
|
||||
|
||||
lsp = {
|
||||
enable = mkEnableOption "Nix LSP support" // {default = config.vim.lsp.enable;};
|
||||
enable = mkEnableOption "Nix LSP support" // {
|
||||
default = config.vim.lsp.enable;
|
||||
};
|
||||
server = mkOption {
|
||||
description = "Nix LSP server to use";
|
||||
type = enum (attrNames servers);
|
||||
|
@ -166,7 +172,9 @@ in {
|
|||
};
|
||||
|
||||
format = {
|
||||
enable = mkEnableOption "Nix formatting" // {default = config.vim.languages.enableFormat;};
|
||||
enable = mkEnableOption "Nix formatting" // {
|
||||
default = config.vim.languages.enableFormat;
|
||||
};
|
||||
|
||||
type = mkOption {
|
||||
description = "Nix formatter to use";
|
||||
|
@ -182,7 +190,9 @@ in {
|
|||
};
|
||||
|
||||
extraDiagnostics = {
|
||||
enable = mkEnableOption "extra Nix diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
||||
enable = mkEnableOption "extra Nix diagnostics" // {
|
||||
default = config.vim.languages.enableExtraDiagnostics;
|
||||
};
|
||||
|
||||
types = diagnostics {
|
||||
langDesc = "Nix";
|
||||
|
@ -236,10 +246,11 @@ in {
|
|||
vim.diagnostics.nvim-lint = {
|
||||
enable = true;
|
||||
linters_by_ft.nix = cfg.extraDiagnostics.types;
|
||||
linters = mkMerge (map (name: {
|
||||
linters = mkMerge (
|
||||
map (name: {
|
||||
${name}.cmd = getExe diagnosticsProviders.${name}.package;
|
||||
})
|
||||
cfg.extraDiagnostics.types);
|
||||
}) cfg.extraDiagnostics.types
|
||||
);
|
||||
};
|
||||
})
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue