mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-30 14:11:03 +01:00
plugins/conform: refactor the autoInstall option implementation
Signed-off-by: saygo-png <saygo.mail@proton.me>
This commit is contained in:
parent
79bfadb32a
commit
96d3538c32
3 changed files with 91 additions and 86 deletions
|
|
@ -8,26 +8,27 @@ let
|
||||||
inherit (builtins)
|
inherit (builtins)
|
||||||
filter
|
filter
|
||||||
isString
|
isString
|
||||||
|
isFunction
|
||||||
isAttrs
|
isAttrs
|
||||||
attrValues
|
attrValues
|
||||||
attrNames
|
attrNames
|
||||||
concatMap
|
concatMap
|
||||||
partition
|
partition
|
||||||
;
|
;
|
||||||
|
inherit (import ./formatter-packages.nix { inherit pkgs lib; }) states formatter-packages;
|
||||||
inherit (import ./formatter-packages.nix { inherit pkgs lib; }) sType formatter-packages;
|
|
||||||
sTypeList = attrValues sType;
|
|
||||||
isSTypeAttrSet = x: lib.elem (x.mark or null) sTypeList;
|
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
cleanMaybePackageList = filter (x: !isSTypeAttrSet x);
|
getPackageOrStateByName =
|
||||||
|
|
||||||
getPackageByName =
|
|
||||||
{ configuredFormatters, overrides }:
|
{ configuredFormatters, overrides }:
|
||||||
name:
|
name:
|
||||||
let
|
let
|
||||||
permittedNames = lib.optionals (lib.isAttrs configuredFormatters) (attrNames configuredFormatters);
|
permittedNames = lib.optionals (lib.isAttrs configuredFormatters) (attrNames configuredFormatters);
|
||||||
isSType = x: elem x sTypeList;
|
stateList = map (state: lib.fix (lib.toFunction state)) (attrValues states);
|
||||||
|
isState =
|
||||||
|
maybePackage:
|
||||||
|
lib.throwIf (isFunction maybePackage) "The '${name}' conform-nvim formatter package is a function" (
|
||||||
|
elem maybePackage stateList
|
||||||
|
);
|
||||||
notFoundMsg = ''
|
notFoundMsg = ''
|
||||||
A package for the conform-nvim formatter '${name}' could not be found.
|
A package for the conform-nvim formatter '${name}' could not be found.
|
||||||
It is not a user defined formatter. Is the formatter name correct?
|
It is not a user defined formatter. Is the formatter name correct?
|
||||||
|
|
@ -36,15 +37,17 @@ rec {
|
||||||
overrides.${name} or formatter-packages.${name} or pkgs.${name}
|
overrides.${name} or formatter-packages.${name} or pkgs.${name}
|
||||||
or (throwIfNot (elem name permittedNames) notFoundMsg null);
|
or (throwIfNot (elem name permittedNames) notFoundMsg null);
|
||||||
in
|
in
|
||||||
if isSType maybePackage then
|
if isState maybePackage then
|
||||||
{
|
{
|
||||||
inherit name;
|
wrong = {
|
||||||
mark = maybePackage;
|
inherit name;
|
||||||
|
mark = maybePackage;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
maybePackage;
|
{ right = maybePackage; };
|
||||||
|
|
||||||
mkWarnsFromMaybePackageList =
|
mkWarnsFromStates =
|
||||||
opts: list:
|
opts: list:
|
||||||
let
|
let
|
||||||
mkWarn =
|
mkWarn =
|
||||||
|
|
@ -61,7 +64,7 @@ rec {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
concatMap mkWarn (filter isSTypeAttrSet list);
|
concatMap mkWarn list;
|
||||||
|
|
||||||
collectFormatters =
|
collectFormatters =
|
||||||
formatters:
|
formatters:
|
||||||
|
|
|
||||||
|
|
@ -245,21 +245,21 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
let
|
let
|
||||||
inherit (cfg.autoInstall) enable enableWarnings;
|
inherit (cfg.autoInstall) enable enableWarnings;
|
||||||
inherit (import ./auto-install.nix { inherit pkgs lib; })
|
inherit (import ./auto-install.nix { inherit pkgs lib; })
|
||||||
getPackageByName
|
getPackageOrStateByName
|
||||||
collectFormatters
|
collectFormatters
|
||||||
cleanMaybePackageList
|
mkWarnsFromStates
|
||||||
mkWarnsFromMaybePackageList
|
|
||||||
;
|
;
|
||||||
getPackageByNameWith = getPackageByName {
|
getPackageOrStateByNameWith = getPackageOrStateByName {
|
||||||
configuredFormatters = cfg.settings.formatters;
|
configuredFormatters = cfg.settings.formatters;
|
||||||
inherit (cfg.autoInstall) overrides;
|
inherit (cfg.autoInstall) overrides;
|
||||||
};
|
};
|
||||||
names = collectFormatters (attrValues cfg.settings.formatters_by_ft or { });
|
formatterNames = collectFormatters (attrValues (cfg.settings.formatters_by_ft or { }));
|
||||||
packageList = map getPackageByNameWith names;
|
packagesAndStates = lib.foldAttrs (item: acc: [ item ] ++ acc) [ ] (
|
||||||
warns = (mkWarnsFromMaybePackageList opts) packageList;
|
map getPackageOrStateByNameWith formatterNames
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
warnings = lib.mkIf (enable && warns != [ ] && enableWarnings) warns;
|
warnings = lib.mkIf (enable && enableWarnings) (mkWarnsFromStates opts packagesAndStates.wrong);
|
||||||
extraPackages = lib.mkIf enable (cleanMaybePackageList packageList);
|
extraPackages = lib.mkIf enable packagesAndStates.right;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,32 +3,34 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with pkgs;
|
with pkgs;
|
||||||
rec {
|
let
|
||||||
sType = {
|
states = {
|
||||||
broken = "broken";
|
broken = _package: "broken";
|
||||||
darwinOnly = "Darwin only";
|
darwinOnly = _package: "Darwin only";
|
||||||
unpackaged = "unpackaged";
|
unpackaged = "unpackaged";
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit states;
|
||||||
formatter-packages = {
|
formatter-packages = {
|
||||||
# 2025-11-15 dependency swift is broken
|
# 2025-11-15 dependency swift is broken
|
||||||
# https://github.com/NixOS/nixpkgs/issues/461474
|
# https://github.com/NixOS/nixpkgs/issues/461474
|
||||||
swift = sType.broken;
|
swift = states.broken swift;
|
||||||
swift_format = sType.broken;
|
swift_format = states.broken swift-format;
|
||||||
swiftformat = sType.broken;
|
swiftformat = states.broken swiftformat;
|
||||||
swiftlint = sType.broken;
|
swiftlint = states.broken swiftlint;
|
||||||
|
|
||||||
# 2025-10-12 build failure on Darwin
|
# 2025-10-12 build failure on Darwin
|
||||||
smlfmt = if stdenv.isDarwin then sType.broken else smlfmt;
|
smlfmt = if stdenv.isDarwin then states.broken smlfmt else smlfmt;
|
||||||
|
|
||||||
# 2025-11-25 build failure
|
# 2025-11-25 build failure
|
||||||
roc = sType.broken;
|
roc = states.broken roc;
|
||||||
# 2025-09-13 build failure
|
# 2025-09-13 build failure
|
||||||
inko = sType.broken;
|
inko = states.broken inko;
|
||||||
# 2025-09-17 build failure
|
# 2025-09-17 build failure
|
||||||
gci = sType.broken;
|
gci = states.broken gci;
|
||||||
# 2025-10-08 build failure (haskellPackages.hindent)
|
# 2025-10-08 build failure (haskellPackages.hindent)
|
||||||
hindent = sType.broken;
|
hindent = states.broken haskellPackages.hindent;
|
||||||
|
|
||||||
format-queries = null; # Uses neovim itself
|
format-queries = null; # Uses neovim itself
|
||||||
init = null; # Internal thingamajig
|
init = null; # Internal thingamajig
|
||||||
|
|
@ -36,55 +38,55 @@ rec {
|
||||||
trim_newlines = null; # Conform native formatter
|
trim_newlines = null; # Conform native formatter
|
||||||
trim_whitespace = null; # Conform native formatter
|
trim_whitespace = null; # Conform native formatter
|
||||||
|
|
||||||
auto_optional = sType.unpackaged;
|
auto_optional = states.unpackaged;
|
||||||
bake = sType.unpackaged;
|
bake = states.unpackaged;
|
||||||
blue = sType.unpackaged;
|
blue = states.unpackaged;
|
||||||
bpfmt = sType.unpackaged;
|
bpfmt = states.unpackaged;
|
||||||
bsfmt = sType.unpackaged;
|
bsfmt = states.unpackaged;
|
||||||
caramel_fmt = sType.unpackaged;
|
caramel_fmt = states.unpackaged;
|
||||||
crlfmt = sType.unpackaged;
|
crlfmt = states.unpackaged;
|
||||||
darker = sType.unpackaged;
|
darker = states.unpackaged;
|
||||||
dcm_fix = sType.unpackaged;
|
dcm_fix = states.unpackaged;
|
||||||
dcm_format = sType.unpackaged;
|
dcm_format = states.unpackaged;
|
||||||
easy-coding-standard = sType.unpackaged;
|
easy-coding-standard = states.unpackaged;
|
||||||
findent = sType.unpackaged;
|
findent = states.unpackaged;
|
||||||
ghokin = sType.unpackaged;
|
ghokin = states.unpackaged;
|
||||||
gluon_fmt = sType.unpackaged;
|
gluon_fmt = states.unpackaged;
|
||||||
grain_format = sType.unpackaged;
|
grain_format = states.unpackaged;
|
||||||
hledger-fmt = sType.unpackaged;
|
hledger-fmt = states.unpackaged;
|
||||||
imba_fmt = sType.unpackaged;
|
imba_fmt = states.unpackaged;
|
||||||
janet-format = sType.unpackaged;
|
janet-format = states.unpackaged;
|
||||||
json_repair = sType.unpackaged;
|
json_repair = states.unpackaged;
|
||||||
liquidsoap-prettier = sType.unpackaged;
|
liquidsoap-prettier = states.unpackaged;
|
||||||
llf = sType.unpackaged;
|
llf = states.unpackaged;
|
||||||
markdown-toc = sType.unpackaged;
|
markdown-toc = states.unpackaged;
|
||||||
markdownfmt = sType.unpackaged;
|
markdownfmt = states.unpackaged;
|
||||||
mdslw = sType.unpackaged;
|
mdslw = states.unpackaged;
|
||||||
mojo_format = sType.unpackaged;
|
mojo_format = states.unpackaged;
|
||||||
nomad_fmt = sType.unpackaged;
|
nomad_fmt = states.unpackaged;
|
||||||
npm-groovy-lint = sType.unpackaged;
|
npm-groovy-lint = states.unpackaged;
|
||||||
packer_fmt = sType.unpackaged;
|
packer_fmt = states.unpackaged;
|
||||||
pangu = sType.unpackaged;
|
pangu = states.unpackaged;
|
||||||
perlimports = sType.unpackaged;
|
perlimports = states.unpackaged;
|
||||||
pint = sType.unpackaged;
|
pint = states.unpackaged;
|
||||||
purs-tidy = sType.unpackaged;
|
purs-tidy = states.unpackaged;
|
||||||
pycln = sType.unpackaged;
|
pycln = states.unpackaged;
|
||||||
pyink = sType.unpackaged;
|
pyink = states.unpackaged;
|
||||||
pymarkdownlnt = sType.unpackaged;
|
pymarkdownlnt = states.unpackaged;
|
||||||
reformat-gherkin = sType.unpackaged;
|
reformat-gherkin = states.unpackaged;
|
||||||
rescript-format = sType.unpackaged;
|
rescript-format = states.unpackaged;
|
||||||
runic = sType.unpackaged;
|
runic = states.unpackaged;
|
||||||
spotless_gradle = sType.unpackaged;
|
spotless_gradle = states.unpackaged;
|
||||||
spotless_maven = sType.unpackaged;
|
spotless_maven = states.unpackaged;
|
||||||
standard-clj = sType.unpackaged;
|
standard-clj = states.unpackaged;
|
||||||
standardjs = sType.unpackaged;
|
standardjs = states.unpackaged;
|
||||||
tclfmt = sType.unpackaged;
|
tclfmt = states.unpackaged;
|
||||||
tlint = sType.unpackaged;
|
tlint = states.unpackaged;
|
||||||
twig-cs-fixer = sType.unpackaged;
|
twig-cs-fixer = states.unpackaged;
|
||||||
typstfmt = sType.unpackaged;
|
typstfmt = states.unpackaged;
|
||||||
vsg = sType.unpackaged;
|
vsg = states.unpackaged;
|
||||||
ziggy = sType.unpackaged;
|
ziggy = states.unpackaged;
|
||||||
ziggy_schema = sType.unpackaged;
|
ziggy_schema = states.unpackaged;
|
||||||
|
|
||||||
inherit (python313Packages) autopep8;
|
inherit (python313Packages) autopep8;
|
||||||
awk = gawk;
|
awk = gawk;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue