Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/efmls-configs: Improve tool installation #705

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 125 additions & 69 deletions plugins/lsp/language-servers/efmls-configs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,119 @@ with lib; let
tools = trivial.importJSON "${pkgs.vimPlugins.efmls-configs-nvim.src}/doc/supported-list.json";

languages = builtins.attrNames tools;

# Mapping of tool name to the nixpkgs package (if any)
toolPkgs = {
inherit
(pkgs)
actionlint
alejandra
ameba
astyle
bashate
beautysh
biome
black
cbfmt
checkmake
clazy
codespell
cppcheck
cpplint
dfmt
djlint
dmd
dprint
fish
flawfinder
gcc
gitlint
gofumpt
golines
golint
hadolint
isort
joker
jq
languagetool
mypy
nixfmt
php
prettierd
proselint
protolint
pylint
rubocop
ruff
rustfmt
scalafmt
selene
shellcheck
shellharden
shfmt
smlfmt
statix
stylua
taplo
uncrustify
vale
yamllint
yapf
;
inherit (pkgs.python3.pkgs) autopep8 flake8 vulture mdformat;
inherit (pkgs.nodePackages) eslint eslint_d prettier alex stylelint textlint write-good;
inherit (pkgs.phpPackages) phpcbf phan phpcs phpstan psalm;
inherit (pkgs.luaPackages) luacheck;
inherit (pkgs.haskellPackages) fourmolu;
ansible_lint = pkgs.ansible-lint;
chktex = pkgs.texliveMedium;
clang_format = pkgs.clang-tools;
clang_tidy = pkgs.clang-tools;
clj_kondo = pkgs.clj-kondo;
cmake_lint = pkgs.cmake-format;
dartfmt = pkgs.dart;
dotnet_format = pkgs.dotnet-runtime;
fish_indent = pkgs.fish;
gofmt = pkgs.go;
goimports = pkgs.go-tools;
golangci_lint = pkgs.golangci-lint;
google_java_format = pkgs.google-java-format;
go_revive = pkgs.revive;
latexindent = pkgs.texliveMedium;
lua_format = pkgs.luaformatter;
markdownlint = pkgs.markdownlint-cli;
mcs = pkgs.mono;
php_cs_fixer = pkgs.phpPackages.php-cs-fixer;
prettier_d = pkgs.prettierd;
slither = pkgs.slither-analyzer;
staticcheck = pkgs.go-tools;
terraform_fmt = pkgs.terraform;
vint = pkgs.vim-vint;
write_good = pkgs.write-good;
yq = pkgs.yq-go;
};
traxys marked this conversation as resolved.
Show resolved Hide resolved
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);
description = ''
Linters/Formatters to skip installing with nixvim. Set to `all` to install no packages
'';
default = [];
};

toolPackages = attrsets.mapAttrs (tool: pkg:
mkOption {
type = types.package;
default = pkg;
description = "Package for ${tool}";
})
toolPkgs;

/*
Users can set the options as follows:

Expand Down Expand Up @@ -76,71 +183,6 @@ in {
};
config = let
cfg = config.plugins.efmls-configs;

# Mapping of tool name to the nixpkgs package (if any)
toolPkgs = {
inherit
(pkgs)
ameba
astyle
bashate
black
cbfmt
clazy
cppcheck
cpplint
dmd
dprint
fish
flawfinder
gcc
golines
golint
hadolint
joker
languagetool
mypy
nixfmt
php
prettierd
proselint
pylint
rubocop
ruff
rustfmt
shellcheck
shfmt
smlfmt
statix
stylua
uncrustify
vale
yamllint
yapf
;
inherit (pkgs.python3.pkgs) autopep8 flake8 vulture;
inherit (pkgs.nodePackages) eslint eslint_d prettier alex stylelint textlint write-good;
inherit (pkgs.phpPackages) phpcbf phan phpcs phpstan psalm;
inherit (pkgs.luaPackages) luacheck;
ansible_lint = pkgs.ansible-lint;
clang_format = pkgs.clang-tools;
clang_tidy = pkgs.clang-tools;
clj_kondo = pkgs.clj-kondo;
dartfmt = pkgs.dart;
dotnet_format = pkgs.dotnet-runtime;
fish_indent = pkgs.fish;
gofmt = pkgs.go;
goimports = pkgs.go-tools;
golangci_lint = pkgs.golangci-lint;
go_revive = pkgs.revive;
lua_format = pkgs.luaformatter;
mcs = pkgs.mono;
php_cs_fixer = pkgs.phpPackages.php-cs-fixer;
slither = pkgs.slither-analyzer;
staticcheck = pkgs.go-tools;
terraform_fmt = pkgs.terraform;
vint = pkgs.vim-vint;
};
toolAsList = tools:
if builtins.isList tools
then tools
Expand All @@ -158,9 +200,18 @@ in {
)
));

pkgsToInstall =
builtins.map (v: toolPkgs.${v})
(builtins.filter (v: builtins.hasAttr v toolPkgs) tools);
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
Expand Down Expand Up @@ -189,11 +240,16 @@ in {
mkIf cfg.enable {
extraPlugins = [cfg.package];

warnings = optional ((builtins.length nixvimPkgs.wrong) > 0) ''
Following tools are not handled by nixvim, please add them to externallyManagedPackages to silence this:
${builtins.concatStringsSep " " nixvimPkgs.wrong}
'';

plugins.lsp.servers.efm = {
enable = true;
extraOptions.settings.languages = setupOptions;
};

extraPackages = [pkgs.efm-langserver] ++ pkgsToInstall;
extraPackages = [pkgs.efm-langserver] ++ (builtins.map (v: toolPkgs.${v}) nixvimPkgs.right);
};
}