mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-29 15:15:13 +02:00
treewide: Reformat with nixfmt
This commit is contained in:
parent
c6281260dc
commit
62f32bfc71
459 changed files with 28139 additions and 26377 deletions
|
@ -5,7 +5,8 @@
|
|||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
with lib;
|
||||
let
|
||||
tools = trivial.importJSON "${pkgs.vimPlugins.efmls-configs-nvim.src}/doc/supported-list.json";
|
||||
|
||||
languages = builtins.attrNames tools;
|
||||
|
@ -71,15 +72,13 @@ with lib; let
|
|||
yamllint
|
||||
yapf
|
||||
;
|
||||
inherit
|
||||
(python3.pkgs)
|
||||
inherit (python3.pkgs)
|
||||
autopep8
|
||||
flake8
|
||||
mdformat
|
||||
vulture
|
||||
;
|
||||
inherit
|
||||
(nodePackages)
|
||||
inherit (nodePackages)
|
||||
eslint
|
||||
eslint_d
|
||||
prettier
|
||||
|
@ -89,20 +88,9 @@ with lib; let
|
|||
textlint
|
||||
write-good
|
||||
;
|
||||
inherit
|
||||
(phpPackages)
|
||||
phan
|
||||
phpstan
|
||||
psalm
|
||||
;
|
||||
inherit
|
||||
(luaPackages)
|
||||
luacheck
|
||||
;
|
||||
inherit
|
||||
(haskellPackages)
|
||||
fourmolu
|
||||
;
|
||||
inherit (phpPackages) phan phpstan psalm;
|
||||
inherit (luaPackages) luacheck;
|
||||
inherit (haskellPackages) fourmolu;
|
||||
ansible_lint = ansible-lint;
|
||||
chktex = texliveMedium;
|
||||
clang_format = clang-tools;
|
||||
|
@ -134,85 +122,86 @@ with lib; let
|
|||
yq = yq-go;
|
||||
};
|
||||
# Filter packages that are not compatible with the current platform
|
||||
toolPkgs =
|
||||
filterAttrs
|
||||
(
|
||||
a: pkg:
|
||||
meta.availableOn
|
||||
pkgs.stdenv.hostPlatform
|
||||
pkg
|
||||
)
|
||||
allToolPkgs;
|
||||
in {
|
||||
toolPkgs = filterAttrs (a: pkg: meta.availableOn pkgs.stdenv.hostPlatform pkg) allToolPkgs;
|
||||
in
|
||||
{
|
||||
options.plugins.efmls-configs = {
|
||||
enable = mkEnableOption "efmls-configs, premade configurations for efm-langserver";
|
||||
|
||||
package = helpers.mkPackageOption "efmls-configs-nvim" pkgs.vimPlugins.efmls-configs-nvim;
|
||||
|
||||
externallyManagedPackages = mkOption {
|
||||
type = types.either (types.enum ["all"]) (types.listOf types.str);
|
||||
type = types.either (types.enum [ "all" ]) (types.listOf types.str);
|
||||
description = ''
|
||||
Linters/Formatters to skip installing with nixvim. Set to `all` to install no packages
|
||||
'';
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
toolPackages = attrsets.mapAttrs (tool: pkg:
|
||||
toolPackages = attrsets.mapAttrs (
|
||||
tool: pkg:
|
||||
mkOption {
|
||||
type = types.package;
|
||||
default = pkg;
|
||||
description = "Package for ${tool}";
|
||||
})
|
||||
toolPkgs;
|
||||
}
|
||||
) toolPkgs;
|
||||
|
||||
/*
|
||||
Users can set the options as follows:
|
||||
Users can set the options as follows:
|
||||
|
||||
{
|
||||
c = {
|
||||
linter = "cppcheck";
|
||||
formatter = ["clang-format" "uncrustify"];
|
||||
};
|
||||
go = {
|
||||
linter = ["djlint" "golangci_lint"];
|
||||
};
|
||||
}
|
||||
*/
|
||||
setup = let
|
||||
languageTools = lang: kind:
|
||||
builtins.map (v: v.name) (
|
||||
if builtins.hasAttr kind tools.${lang}
|
||||
then tools.${lang}.${kind}
|
||||
else []
|
||||
);
|
||||
|
||||
miscLinters = languageTools "misc" "linters";
|
||||
miscFormatters = languageTools "misc" "formatters";
|
||||
|
||||
mkChooseOption = lang: kind: possible: let
|
||||
toolType = with types; either (enum possible) helpers.nixvimTypes.rawLua;
|
||||
in
|
||||
mkOption {
|
||||
type = with types; either toolType (listOf toolType);
|
||||
default = [];
|
||||
description = "${kind} tools for ${lang}";
|
||||
{
|
||||
c = {
|
||||
linter = "cppcheck";
|
||||
formatter = ["clang-format" "uncrustify"];
|
||||
};
|
||||
in
|
||||
go = {
|
||||
linter = ["djlint" "golangci_lint"];
|
||||
};
|
||||
}
|
||||
*/
|
||||
setup =
|
||||
let
|
||||
languageTools =
|
||||
lang: kind:
|
||||
builtins.map (v: v.name) (
|
||||
if builtins.hasAttr kind tools.${lang} then tools.${lang}.${kind} else [ ]
|
||||
);
|
||||
|
||||
miscLinters = languageTools "misc" "linters";
|
||||
miscFormatters = languageTools "misc" "formatters";
|
||||
|
||||
mkChooseOption =
|
||||
lang: kind: possible:
|
||||
let
|
||||
toolType = with types; either (enum possible) helpers.nixvimTypes.rawLua;
|
||||
in
|
||||
mkOption {
|
||||
type = with types; either toolType (listOf toolType);
|
||||
default = [ ];
|
||||
description = "${kind} tools for ${lang}";
|
||||
};
|
||||
in
|
||||
mkOption {
|
||||
type = types.submodule {
|
||||
freeformType = types.attrs;
|
||||
|
||||
options =
|
||||
(builtins.listToAttrs (builtins.map (lang: let
|
||||
langTools = languageTools lang;
|
||||
in {
|
||||
name = lang;
|
||||
value = {
|
||||
linter = mkChooseOption lang "linter" ((langTools "linters") ++ miscLinters);
|
||||
formatter = mkChooseOption lang "formatter" ((langTools "formatters") ++ miscFormatters);
|
||||
};
|
||||
})
|
||||
languages))
|
||||
(builtins.listToAttrs (
|
||||
builtins.map (
|
||||
lang:
|
||||
let
|
||||
langTools = languageTools lang;
|
||||
in
|
||||
{
|
||||
name = lang;
|
||||
value = {
|
||||
linter = mkChooseOption lang "linter" ((langTools "linters") ++ miscLinters);
|
||||
formatter = mkChooseOption lang "formatter" ((langTools "formatters") ++ miscFormatters);
|
||||
};
|
||||
}
|
||||
) languages
|
||||
))
|
||||
// {
|
||||
all = {
|
||||
linter = mkChooseOption "all languages" "linter" miscLinters;
|
||||
|
@ -221,67 +210,69 @@ in {
|
|||
};
|
||||
};
|
||||
description = "Configuration for each filetype. Use `all` to match any filetype.";
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
config = let
|
||||
cfg = config.plugins.efmls-configs;
|
||||
toolAsList = tools:
|
||||
if builtins.isList tools
|
||||
then tools
|
||||
else [tools];
|
||||
config =
|
||||
let
|
||||
cfg = config.plugins.efmls-configs;
|
||||
toolAsList = tools: if builtins.isList tools then tools else [ tools ];
|
||||
|
||||
# Tools that have been selected by the user
|
||||
tools = lists.unique (builtins.filter builtins.isString (
|
||||
builtins.concatLists (
|
||||
builtins.map ({
|
||||
linter ? [],
|
||||
formatter ? [],
|
||||
}:
|
||||
(toolAsList linter) ++ (toolAsList formatter))
|
||||
(builtins.attrValues cfg.setup)
|
||||
)
|
||||
));
|
||||
|
||||
pkgsForTools = let
|
||||
partitionFn =
|
||||
if cfg.externallyManagedPackages == "all"
|
||||
then _: false
|
||||
else t: !(builtins.elem t cfg.externallyManagedPackages);
|
||||
partition = lists.partition partitionFn tools;
|
||||
in {
|
||||
nixvim = partition.right;
|
||||
external = partition.wrong;
|
||||
};
|
||||
|
||||
nixvimPkgs = lists.partition (v: builtins.hasAttr v cfg.toolPackages) pkgsForTools.nixvim;
|
||||
|
||||
mkToolOption = kind: opt:
|
||||
builtins.map
|
||||
(tool:
|
||||
if builtins.isString tool
|
||||
then helpers.mkRaw "require 'efmls-configs.${kind}.${tool}'"
|
||||
else tool)
|
||||
(toolAsList opt);
|
||||
|
||||
setupOptions =
|
||||
(builtins.mapAttrs (
|
||||
_: {
|
||||
linter ? [],
|
||||
formatter ? [],
|
||||
}:
|
||||
(mkToolOption "linters" linter)
|
||||
++ (mkToolOption "formatters" formatter)
|
||||
# Tools that have been selected by the user
|
||||
tools = lists.unique (
|
||||
builtins.filter builtins.isString (
|
||||
builtins.concatLists (
|
||||
builtins.map (
|
||||
{
|
||||
linter ? [ ],
|
||||
formatter ? [ ],
|
||||
}:
|
||||
(toolAsList linter) ++ (toolAsList formatter)
|
||||
) (builtins.attrValues cfg.setup)
|
||||
)
|
||||
)
|
||||
(attrsets.filterAttrs (v: _: v != "all") cfg.setup))
|
||||
// {
|
||||
"=" =
|
||||
(mkToolOption "linters" cfg.setup.all.linter)
|
||||
++ (mkToolOption "formatters" cfg.setup.all.formatter);
|
||||
};
|
||||
in
|
||||
);
|
||||
|
||||
pkgsForTools =
|
||||
let
|
||||
partitionFn =
|
||||
if cfg.externallyManagedPackages == "all" then
|
||||
_: false
|
||||
else
|
||||
t: !(builtins.elem t cfg.externallyManagedPackages);
|
||||
partition = lists.partition partitionFn tools;
|
||||
in
|
||||
{
|
||||
nixvim = partition.right;
|
||||
external = partition.wrong;
|
||||
};
|
||||
|
||||
nixvimPkgs = lists.partition (v: builtins.hasAttr v cfg.toolPackages) pkgsForTools.nixvim;
|
||||
|
||||
mkToolOption =
|
||||
kind: opt:
|
||||
builtins.map (
|
||||
tool:
|
||||
if builtins.isString tool then helpers.mkRaw "require 'efmls-configs.${kind}.${tool}'" else tool
|
||||
) (toolAsList opt);
|
||||
|
||||
setupOptions =
|
||||
(builtins.mapAttrs (
|
||||
_:
|
||||
{
|
||||
linter ? [ ],
|
||||
formatter ? [ ],
|
||||
}:
|
||||
(mkToolOption "linters" linter) ++ (mkToolOption "formatters" formatter)
|
||||
) (attrsets.filterAttrs (v: _: v != "all") cfg.setup))
|
||||
// {
|
||||
"=" =
|
||||
(mkToolOption "linters" cfg.setup.all.linter)
|
||||
++ (mkToolOption "formatters" cfg.setup.all.formatter);
|
||||
};
|
||||
in
|
||||
mkIf cfg.enable {
|
||||
extraPlugins = [cfg.package];
|
||||
extraPlugins = [ cfg.package ];
|
||||
|
||||
warnings = optional ((builtins.length nixvimPkgs.wrong) > 0) ''
|
||||
Nixvim (plugins.efmls-configs): Following tools are not handled by nixvim, please add them to externallyManagedPackages to silence this:
|
||||
|
@ -293,14 +284,8 @@ in {
|
|||
extraOptions.settings.languages = setupOptions;
|
||||
};
|
||||
|
||||
extraPackages =
|
||||
[
|
||||
pkgs.efm-langserver
|
||||
]
|
||||
++ (
|
||||
builtins.map
|
||||
(v: cfg.toolPackages.${v})
|
||||
nixvimPkgs.right
|
||||
);
|
||||
extraPackages = [
|
||||
pkgs.efm-langserver
|
||||
] ++ (builtins.map (v: cfg.toolPackages.${v}) nixvimPkgs.right);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue