From a51108e879cfabd09507b2f4c3527a8ed7e85dc8 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 1 Feb 2025 07:31:51 +0300 Subject: [PATCH] formatter/conform-nvim: init --- .../plugins/formatter/conform-nvim/config.nix | 20 +++++++ .../formatter/conform-nvim/conform-nvim.nix | 56 +++++++++++++++++++ .../formatter/conform-nvim/default.nix | 6 ++ modules/plugins/formatter/default.nix | 3 + 4 files changed, 85 insertions(+) create mode 100644 modules/plugins/formatter/conform-nvim/config.nix create mode 100644 modules/plugins/formatter/conform-nvim/conform-nvim.nix create mode 100644 modules/plugins/formatter/conform-nvim/default.nix create mode 100644 modules/plugins/formatter/default.nix diff --git a/modules/plugins/formatter/conform-nvim/config.nix b/modules/plugins/formatter/conform-nvim/config.nix new file mode 100644 index 00000000..0b83d813 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/config.nix @@ -0,0 +1,20 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.formatter.conform-nvim; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = ["conform-nvim"]; + pluginRC.conform-nvim = entryAnywhere '' + require("conform").setup(${toLuaObject cfg.setupOpts}) + ''; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/conform-nvim.nix b/modules/plugins/formatter/conform-nvim/conform-nvim.nix new file mode 100644 index 00000000..423a4f44 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/conform-nvim.nix @@ -0,0 +1,56 @@ +{ + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.types) attrs enum; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.nvim.lua) mkLuaInline; +in { + options.vim.formatter.conform-nvim = { + enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]"; + setupOpts = mkPluginSetupOption "conform.nvim" { + formatters_by_ft = mkOption { + type = attrs; + default = {}; + example = {lua = ["stylua"];}; + description = '' + Map of filetype to formatters. This option takes a set of + `key = value` format where the `value will` be converted + to its Lua equivalent. You are responsible for passing the + correct Nix data types to generate a correct Lua value that + conform is able to accept. + ''; + }; + + default_format_opts = mkOption { + type = attrs; + default = {lsp_format = "fallback";}; + description = "Default values when calling `conform.format()`"; + }; + + format_on_save = mkOption { + type = attrs; + default = { + lsp_format = "fallback"; + timeout_ms = 500; + }; + description = '' + Table that will be passed to `conform.format()`. If this + is set, Conform will run the formatter on save. + ''; + }; + + format_after_save = mkOption { + type = attrs; + default = {lsp_format = "fallback";}; + description = '' + Table that will be passed to `conform.format()`. If this + is set, Conform will run the formatter asynchronously after + save. + ''; + }; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/default.nix b/modules/plugins/formatter/conform-nvim/default.nix new file mode 100644 index 00000000..56c90f3f --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./conform-nvim.nix + ./config.nix + ]; +} diff --git a/modules/plugins/formatter/default.nix b/modules/plugins/formatter/default.nix new file mode 100644 index 00000000..f57ad66a --- /dev/null +++ b/modules/plugins/formatter/default.nix @@ -0,0 +1,3 @@ +{ + imports = [./conform-nvim]; +}