mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-12-08 13:13:55 +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
|
|
@ -7,9 +7,9 @@
|
|||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.types) enum package;
|
||||
inherit (lib.types) enum;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.nvim.types) mkGrammarOption singleOrListOf;
|
||||
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
|
||||
|
|
@ -19,35 +19,31 @@
|
|||
packages = [pkgs.rPackages.languageserver];
|
||||
};
|
||||
|
||||
defaultFormat = "format_r";
|
||||
defaultFormat = ["format_r"];
|
||||
formats = {
|
||||
styler = {
|
||||
package = pkgs.rWrapper.override {
|
||||
packages = [pkgs.rPackages.styler];
|
||||
};
|
||||
config = {
|
||||
command = "${cfg.format.package}/bin/R";
|
||||
};
|
||||
command = let
|
||||
pkg = pkgs.rWrapper.override {packages = [pkgs.rPackages.styler];};
|
||||
in "${pkg}/bin/R";
|
||||
};
|
||||
|
||||
format_r = {
|
||||
package = pkgs.rWrapper.override {
|
||||
packages = [pkgs.rPackages.formatR];
|
||||
};
|
||||
config = {
|
||||
command = "${cfg.format.package}/bin/R";
|
||||
stdin = true;
|
||||
args = [
|
||||
"--slave"
|
||||
"--no-restore"
|
||||
"--no-save"
|
||||
"-s"
|
||||
"-e"
|
||||
''formatR::tidy_source(source="stdin")''
|
||||
];
|
||||
# TODO: range_args seem to be possible
|
||||
# https://github.com/nvimtools/none-ls.nvim/blob/main/lua/null-ls/builtins/formatting/format_r.lua
|
||||
};
|
||||
command = let
|
||||
pkg = pkgs.rWrapper.override {
|
||||
packages = [pkgs.rPackages.formatR];
|
||||
};
|
||||
in "${pkg}/bin/R";
|
||||
stdin = true;
|
||||
args = [
|
||||
"--slave"
|
||||
"--no-restore"
|
||||
"--no-save"
|
||||
"-s"
|
||||
"-e"
|
||||
''formatR::tidy_source(source="stdin")''
|
||||
];
|
||||
# TODO: range_args seem to be possible
|
||||
# https://github.com/nvimtools/none-ls.nvim/blob/main/lua/null-ls/builtins/formatting/format_r.lua
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -77,7 +73,7 @@ in {
|
|||
enable = mkEnableOption "R LSP support" // {default = config.vim.lsp.enable;};
|
||||
|
||||
servers = mkOption {
|
||||
type = singleOrListOf (enum (attrNames servers));
|
||||
type = deprecatedSingleOrListOf "vim.language.r.lsp.servers" (enum (attrNames servers));
|
||||
default = defaultServers;
|
||||
description = "R LSP server to use";
|
||||
};
|
||||
|
|
@ -87,16 +83,10 @@ in {
|
|||
enable = mkEnableOption "R formatting" // {default = config.vim.languages.enableFormat;};
|
||||
|
||||
type = mkOption {
|
||||
type = enum (attrNames formats);
|
||||
type = deprecatedSingleOrListOf "vim.language.r.format.type" (enum (attrNames formats));
|
||||
default = defaultFormat;
|
||||
description = "R formatter to use";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = package;
|
||||
default = formats.${cfg.format.type}.package;
|
||||
description = "R formatter package";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -109,8 +99,15 @@ in {
|
|||
(mkIf cfg.format.enable {
|
||||
vim.formatter.conform-nvim = {
|
||||
enable = true;
|
||||
setupOpts.formatters_by_ft.r = [cfg.format.type];
|
||||
setupOpts.formatters.${cfg.format.type} = formats.${cfg.format.type}.config;
|
||||
setupOpts = {
|
||||
formatters_by_ft.r = cfg.format.type;
|
||||
formatters =
|
||||
mapListToAttrs (name: {
|
||||
inherit name;
|
||||
value = formats.${name};
|
||||
})
|
||||
cfg.format.type;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue