1
0
Fork 0
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:
saygo-png 2025-11-27 00:40:49 +01:00 committed by Matt Sturgeon
parent 79bfadb32a
commit 96d3538c32
3 changed files with 91 additions and 86 deletions

View file

@ -8,26 +8,27 @@ let
inherit (builtins)
filter
isString
isFunction
isAttrs
attrValues
attrNames
concatMap
partition
;
inherit (import ./formatter-packages.nix { inherit pkgs lib; }) sType formatter-packages;
sTypeList = attrValues sType;
isSTypeAttrSet = x: lib.elem (x.mark or null) sTypeList;
inherit (import ./formatter-packages.nix { inherit pkgs lib; }) states formatter-packages;
in
rec {
cleanMaybePackageList = filter (x: !isSTypeAttrSet x);
getPackageByName =
getPackageOrStateByName =
{ configuredFormatters, overrides }:
name:
let
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 = ''
A package for the conform-nvim formatter '${name}' could not be found.
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}
or (throwIfNot (elem name permittedNames) notFoundMsg null);
in
if isSType maybePackage then
if isState maybePackage then
{
inherit name;
mark = maybePackage;
wrong = {
inherit name;
mark = maybePackage;
};
}
else
maybePackage;
{ right = maybePackage; };
mkWarnsFromMaybePackageList =
mkWarnsFromStates =
opts: list:
let
mkWarn =
@ -61,7 +64,7 @@ rec {
}
];
in
concatMap mkWarn (filter isSTypeAttrSet list);
concatMap mkWarn list;
collectFormatters =
formatters:

View file

@ -245,21 +245,21 @@ lib.nixvim.plugins.mkNeovimPlugin {
let
inherit (cfg.autoInstall) enable enableWarnings;
inherit (import ./auto-install.nix { inherit pkgs lib; })
getPackageByName
getPackageOrStateByName
collectFormatters
cleanMaybePackageList
mkWarnsFromMaybePackageList
mkWarnsFromStates
;
getPackageByNameWith = getPackageByName {
getPackageOrStateByNameWith = getPackageOrStateByName {
configuredFormatters = cfg.settings.formatters;
inherit (cfg.autoInstall) overrides;
};
names = collectFormatters (attrValues cfg.settings.formatters_by_ft or { });
packageList = map getPackageByNameWith names;
warns = (mkWarnsFromMaybePackageList opts) packageList;
formatterNames = collectFormatters (attrValues (cfg.settings.formatters_by_ft or { }));
packagesAndStates = lib.foldAttrs (item: acc: [ item ] ++ acc) [ ] (
map getPackageOrStateByNameWith formatterNames
);
in
{
warnings = lib.mkIf (enable && warns != [ ] && enableWarnings) warns;
extraPackages = lib.mkIf enable (cleanMaybePackageList packageList);
warnings = lib.mkIf (enable && enableWarnings) (mkWarnsFromStates opts packagesAndStates.wrong);
extraPackages = lib.mkIf enable packagesAndStates.right;
};
}

View file

@ -3,32 +3,34 @@
...
}:
with pkgs;
rec {
sType = {
broken = "broken";
darwinOnly = "Darwin only";
let
states = {
broken = _package: "broken";
darwinOnly = _package: "Darwin only";
unpackaged = "unpackaged";
};
in
{
inherit states;
formatter-packages = {
# 2025-11-15 dependency swift is broken
# https://github.com/NixOS/nixpkgs/issues/461474
swift = sType.broken;
swift_format = sType.broken;
swiftformat = sType.broken;
swiftlint = sType.broken;
swift = states.broken swift;
swift_format = states.broken swift-format;
swiftformat = states.broken swiftformat;
swiftlint = states.broken swiftlint;
# 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
roc = sType.broken;
roc = states.broken roc;
# 2025-09-13 build failure
inko = sType.broken;
inko = states.broken inko;
# 2025-09-17 build failure
gci = sType.broken;
gci = states.broken gci;
# 2025-10-08 build failure (haskellPackages.hindent)
hindent = sType.broken;
hindent = states.broken haskellPackages.hindent;
format-queries = null; # Uses neovim itself
init = null; # Internal thingamajig
@ -36,55 +38,55 @@ rec {
trim_newlines = null; # Conform native formatter
trim_whitespace = null; # Conform native formatter
auto_optional = sType.unpackaged;
bake = sType.unpackaged;
blue = sType.unpackaged;
bpfmt = sType.unpackaged;
bsfmt = sType.unpackaged;
caramel_fmt = sType.unpackaged;
crlfmt = sType.unpackaged;
darker = sType.unpackaged;
dcm_fix = sType.unpackaged;
dcm_format = sType.unpackaged;
easy-coding-standard = sType.unpackaged;
findent = sType.unpackaged;
ghokin = sType.unpackaged;
gluon_fmt = sType.unpackaged;
grain_format = sType.unpackaged;
hledger-fmt = sType.unpackaged;
imba_fmt = sType.unpackaged;
janet-format = sType.unpackaged;
json_repair = sType.unpackaged;
liquidsoap-prettier = sType.unpackaged;
llf = sType.unpackaged;
markdown-toc = sType.unpackaged;
markdownfmt = sType.unpackaged;
mdslw = sType.unpackaged;
mojo_format = sType.unpackaged;
nomad_fmt = sType.unpackaged;
npm-groovy-lint = sType.unpackaged;
packer_fmt = sType.unpackaged;
pangu = sType.unpackaged;
perlimports = sType.unpackaged;
pint = sType.unpackaged;
purs-tidy = sType.unpackaged;
pycln = sType.unpackaged;
pyink = sType.unpackaged;
pymarkdownlnt = sType.unpackaged;
reformat-gherkin = sType.unpackaged;
rescript-format = sType.unpackaged;
runic = sType.unpackaged;
spotless_gradle = sType.unpackaged;
spotless_maven = sType.unpackaged;
standard-clj = sType.unpackaged;
standardjs = sType.unpackaged;
tclfmt = sType.unpackaged;
tlint = sType.unpackaged;
twig-cs-fixer = sType.unpackaged;
typstfmt = sType.unpackaged;
vsg = sType.unpackaged;
ziggy = sType.unpackaged;
ziggy_schema = sType.unpackaged;
auto_optional = states.unpackaged;
bake = states.unpackaged;
blue = states.unpackaged;
bpfmt = states.unpackaged;
bsfmt = states.unpackaged;
caramel_fmt = states.unpackaged;
crlfmt = states.unpackaged;
darker = states.unpackaged;
dcm_fix = states.unpackaged;
dcm_format = states.unpackaged;
easy-coding-standard = states.unpackaged;
findent = states.unpackaged;
ghokin = states.unpackaged;
gluon_fmt = states.unpackaged;
grain_format = states.unpackaged;
hledger-fmt = states.unpackaged;
imba_fmt = states.unpackaged;
janet-format = states.unpackaged;
json_repair = states.unpackaged;
liquidsoap-prettier = states.unpackaged;
llf = states.unpackaged;
markdown-toc = states.unpackaged;
markdownfmt = states.unpackaged;
mdslw = states.unpackaged;
mojo_format = states.unpackaged;
nomad_fmt = states.unpackaged;
npm-groovy-lint = states.unpackaged;
packer_fmt = states.unpackaged;
pangu = states.unpackaged;
perlimports = states.unpackaged;
pint = states.unpackaged;
purs-tidy = states.unpackaged;
pycln = states.unpackaged;
pyink = states.unpackaged;
pymarkdownlnt = states.unpackaged;
reformat-gherkin = states.unpackaged;
rescript-format = states.unpackaged;
runic = states.unpackaged;
spotless_gradle = states.unpackaged;
spotless_maven = states.unpackaged;
standard-clj = states.unpackaged;
standardjs = states.unpackaged;
tclfmt = states.unpackaged;
tlint = states.unpackaged;
twig-cs-fixer = states.unpackaged;
typstfmt = states.unpackaged;
vsg = states.unpackaged;
ziggy = states.unpackaged;
ziggy_schema = states.unpackaged;
inherit (python313Packages) autopep8;
awk = gawk;