diff --git a/modules/plugins/formatter/conform-nvim/conform-nvim.nix b/modules/plugins/formatter/conform-nvim/conform-nvim.nix index 423a4f44..ee86be54 100644 --- a/modules/plugins/formatter/conform-nvim/conform-nvim.nix +++ b/modules/plugins/formatter/conform-nvim/conform-nvim.nix @@ -1,18 +1,48 @@ { - pkgs, + config, lib, ... }: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrs enum; - inherit (lib.nvim.types) mkPluginSetupOption; - inherit (lib.nvim.lua) mkLuaInline; + inherit (lib.types) attrsOf anything list either; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; + + cfg = config.vim.formatter.conform-nvim; in { options.vim.formatter.conform-nvim = { enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]"; + + # This is to declare all custom formatters nvf uses for language modules in a single + # module option so that + # 1. Modules can refer to each others' formatters + # 2. If users already have some of the formatters in PATH, they can override the attrset. + # Values set here will be passed directly to setupOpts.formatters. + configuredFormatters = mkOption { + type = attrsOf anything; + default = {}; + example = literalExpression '' + { + yamlfix.command = "$${lib.getExe pkgs.yamlfix}"; + rustfmt.env = { + RUST_SRC_PATH = "$${pkgs.rustPlatform.rustLibSrc}"; + }; + } + ''; + description = "Override options for formatters provided by conform.nvim"; + }; + setupOpts = mkPluginSetupOption "conform.nvim" { + formatters = mkOption { + type = attrsOf anything; + default = cfg.configuredFormatters; + description = '' + Attribute set containing overrides for conform's own formatters, or + new formatters to be recognized by conform in, e.g., `formatters_by_ft` + ''; + }; + formatters_by_ft = mkOption { - type = attrs; + type = either (attrsOf list) luaInline; default = {}; example = {lua = ["stylua"];}; description = '' @@ -25,13 +55,13 @@ in { }; default_format_opts = mkOption { - type = attrs; + type = attrsOf anything; default = {lsp_format = "fallback";}; description = "Default values when calling `conform.format()`"; }; format_on_save = mkOption { - type = attrs; + type = attrsOf anything; default = { lsp_format = "fallback"; timeout_ms = 500; @@ -43,7 +73,7 @@ in { }; format_after_save = mkOption { - type = attrs; + type = attrsOf anything; default = {lsp_format = "fallback";}; description = '' Table that will be passed to `conform.format()`. If this