mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-12-08 21:23:53 +00:00
languages/formatters: allow multiple formatters (#1103)
* language/python: allow multiple formatters * package: add prettier-plugin-astro * language/astro: fix prettier, remove prettierd * package: add prettier-plugin-svelte * language/svelte: fix prettier, remove prettierd * languages: allow listOf format.type * deprecations: add warnings for removed format options * ruby: remove unused variable * nix: fix outdated references to format.package * docs: update release note * treewide: warn deprecation in singleOrListOf * conform: add definitions for setupOpts.formatters
This commit is contained in:
parent
a87439ed3c
commit
d5da1a14c3
47 changed files with 641 additions and 488 deletions
|
|
@ -4,13 +4,14 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (builtins) attrNames warn;
|
||||
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
||||
inherit (lib.lists) flatten;
|
||||
inherit (lib.meta) getExe getExe';
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.types) enum package bool;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
inherit (lib.nvim.types) singleOrListOf;
|
||||
inherit (lib.nvim.types) deprecatedSingleOrListOf;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.dag) entryBefore;
|
||||
|
||||
|
|
@ -126,34 +127,22 @@
|
|||
};
|
||||
};
|
||||
|
||||
defaultFormat = "black";
|
||||
defaultFormat = ["black"];
|
||||
formats = {
|
||||
black = {
|
||||
package = pkgs.black;
|
||||
command = getExe pkgs.black;
|
||||
};
|
||||
|
||||
isort = {
|
||||
package = pkgs.isort;
|
||||
command = getExe pkgs.isort;
|
||||
};
|
||||
|
||||
black-and-isort = {
|
||||
package = pkgs.writeShellApplication {
|
||||
name = "black";
|
||||
runtimeInputs = [pkgs.black pkgs.isort];
|
||||
text = ''
|
||||
black --quiet - "$@" | isort --profile black -
|
||||
'';
|
||||
};
|
||||
};
|
||||
# dummy option for backwards compat
|
||||
black-and-isort = {};
|
||||
|
||||
ruff = {
|
||||
package = pkgs.writeShellApplication {
|
||||
name = "ruff";
|
||||
runtimeInputs = [pkgs.ruff];
|
||||
text = ''
|
||||
ruff format -
|
||||
'';
|
||||
};
|
||||
command = getExe pkgs.ruff;
|
||||
args = ["format" "-"];
|
||||
};
|
||||
|
||||
ruff-check = {
|
||||
|
|
@ -246,7 +235,7 @@ in {
|
|||
enable = mkEnableOption "Python LSP support" // {default = config.vim.lsp.enable;};
|
||||
|
||||
servers = mkOption {
|
||||
type = singleOrListOf (enum (attrNames servers));
|
||||
type = deprecatedSingleOrListOf "vim.language.python.lsp.servers" (enum (attrNames servers));
|
||||
default = defaultServers;
|
||||
description = "Python LSP server to use";
|
||||
};
|
||||
|
|
@ -256,15 +245,9 @@ in {
|
|||
enable = mkEnableOption "Python formatting" // {default = config.vim.languages.enableFormat;};
|
||||
|
||||
type = mkOption {
|
||||
type = enum (attrNames formats);
|
||||
type = deprecatedSingleOrListOf "vim.language.python.format.type" (enum (attrNames formats));
|
||||
default = defaultFormat;
|
||||
description = "Python formatter to use";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = package;
|
||||
default = formats.${cfg.format.type}.package;
|
||||
description = "Python formatter package";
|
||||
description = "Python formatters to use";
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -333,21 +316,27 @@ in {
|
|||
})
|
||||
|
||||
(mkIf cfg.format.enable {
|
||||
vim.formatter.conform-nvim = {
|
||||
vim.formatter.conform-nvim = let
|
||||
names = flatten (map (type:
|
||||
if type == "black-and-isort"
|
||||
then
|
||||
warn ''
|
||||
vim.languages.python.format.type: "black-and-isort" is deprecated,
|
||||
use `["black" "isort"]` instead.
|
||||
'' ["black" "isort"]
|
||||
else type)
|
||||
cfg.format.type);
|
||||
in {
|
||||
enable = true;
|
||||
# HACK: I'm planning to remove these soon so I just took the easiest way out
|
||||
setupOpts.formatters_by_ft.python =
|
||||
if cfg.format.type == "black-and-isort"
|
||||
then ["black"]
|
||||
else [cfg.format.type];
|
||||
setupOpts.formatters =
|
||||
if (cfg.format.type == "black-and-isort")
|
||||
then {
|
||||
black.command = "${cfg.format.package}/bin/black";
|
||||
}
|
||||
else {
|
||||
${cfg.format.type}.command = getExe cfg.format.package;
|
||||
};
|
||||
setupOpts = {
|
||||
formatters_by_ft.python = names;
|
||||
formatters =
|
||||
mapListToAttrs (name: {
|
||||
inherit name;
|
||||
value = formats.${name};
|
||||
})
|
||||
names;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue