From cf335569c2d498c23e4855f60635be9c9cd3b923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Wed, 7 May 2025 16:36:38 +0200 Subject: [PATCH] feat(jj): configure jj fix with formatters from nvim Export nvim formatters as `jj fix` tools. --- modules/hm/dev.nix | 59 ++++++++++++++++++++++++++++++++++ modules/nixvim/dev-plugins.nix | 4 +-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/modules/hm/dev.nix b/modules/hm/dev.nix index 2c2d898..40d52b9 100644 --- a/modules/hm/dev.nix +++ b/modules/hm/dev.nix @@ -6,6 +6,64 @@ }: let cfg = config.jhome.dev; + nvimFormatters = builtins.mapAttrs ( + name: value: value.command + ) config.nixvim.plugins.conform-nvim.settings.formatters; + jjFormatters = + let + ext = extension: "glob:'**/*.${ext}'"; + in + { + fish = cmd: { + command = [ cmd ]; + patterns = [ (ext "fish") ]; + }; + nixfmt = cmd: { + command = [ + cmd + "--filename=$path" + ]; + patterns = [ (ext "nix") ]; + }; + shfmt = cmd: { + command = [ + cmd + "--filename" + "$path" + "-" + ]; + patterns = [ + (ext "sh") + (ext "bash") + ]; + }; + stylua = cmd: { + command = [ + cmd + "--stdin-filepath=$path" + "-" + ]; + patterns = [ (ext "lua") ]; + }; + taplo = cmd: { + command = [ + cmd + "--stdin-filepath=$path" + "-" + ]; + patterns = [ (ext "toml") ]; + }; + yamlfmt = cmd: { + command = [ + cmd + "-in" + ]; + patterns = [ + (ext "yaml") + (ext "yml") + ]; + }; + }; in { config = @@ -68,6 +126,7 @@ in package = pkgs.unstable.jujutsu; settings = { ui.pager = "bat"; + fix.tools = builtins.mapAttrs (tool: cmd: jjFormatters.${tool} cmd) nvimFmt; # mimic git commit --verbose by adding a diff templates.draft_commit_description = '' concat( diff --git a/modules/nixvim/dev-plugins.nix b/modules/nixvim/dev-plugins.nix index 53b22ca..eb47a0e 100644 --- a/modules/nixvim/dev-plugins.nix +++ b/modules/nixvim/dev-plugins.nix @@ -95,12 +95,12 @@ in enable = true; settings = { formatters = { - fish.command = lib.getExe pkgs.fish; + fish.command = lib.getExe' pkgs.fish "fish_indent"; nixfmt.command = lib.getExe pkgs.nixfmt-rfc-style; shfmt.command = lib.getExe pkgs.shfmt; stylua.command = lib.getExe pkgs.stylua; taplo.command = lib.getExe pkgs.taplo; - yamlfmt.command = lib.getExe' pkgs.yamlfmt "fish_indent"; + yamlfmt.command = lib.getExe pkgs.yamlfmt; }; formatters_by_ft = { "_" = [ "trim_whitespace" ];