diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index ffdccb8e..fe4990bc 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -388,6 +388,8 @@ - Fix `languages.ts` registration of formatters. +- Added `asmfmt` and `nasmfmt` formatters to `languages.asm`. + - Added `biome-check` and `biome-organize-imports` formatters to `languages.ts`. - Added [`biomejs`](https://biomejs.dev/) as extra diagnostics provider to diff --git a/modules/plugins/languages/asm.nix b/modules/plugins/languages/asm.nix index 41b9f4bd..fbed0e93 100644 --- a/modules/plugins/languages/asm.nix +++ b/modules/plugins/languages/asm.nix @@ -4,15 +4,37 @@ lib, ... }: let - inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum listOf; + inherit (builtins) attrNames; inherit (lib) genAttrs; + inherit (lib.generators) mkLuaInline; + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib.types) enum listOf; cfg = config.vim.languages.assembly; defaultServers = ["asm-lsp"]; servers = ["asm-lsp"]; + + defaultFormat = ["asmfmt"]; + formats = { + asmfmt = { + command = getExe pkgs.asmfmt; + }; + nasmfmt = { + command = getExe pkgs.nasmfmt; + args = mkLuaInline '' + function(self, ctx) + return { + "--ii", ctx.shiftwidth, + "$FILENAME", + } + end + ''; + }; + }; in { options.vim.languages.assembly = { enable = mkEnableOption "Assembly support"; @@ -42,6 +64,20 @@ in { description = "Assembly LSP server to use"; }; }; + + format = { + enable = + mkEnableOption "Assembly formatting" + // { + default = config.vim.languages.enableFormat; + defaultText = literalExpression "config.vim.languages.enableFormat"; + }; + type = mkOption { + type = listOf (enum (attrNames formats)); + default = defaultFormat; + description = "Assembly formatter to use"; + }; + }; }; config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { @@ -57,9 +93,43 @@ in { vim.lsp = { presets = genAttrs cfg.lsp.servers (_: {enable = true;}); servers = genAttrs cfg.lsp.servers (_: { - filetypes = ["asm" "nasm" "masm" "vmasm" "fasm" "tasm" "tiasm" "asm68k" "asm8300"]; + filetypes = [ + "asm" + "nasm" + "masm" + "vmasm" + "fasm" + "tasm" + "tiasm" + "asm68k" + "asmh8300" + ]; }); }; }) + + (mkIf cfg.format.enable { + vim.formatter.conform-nvim = { + enable = true; + setupOpts = { + formatters_by_ft = { + asm = cfg.format.type; + nasm = cfg.format.type; + masm = cfg.format.type; + vmasm = cfg.format.type; + tasm = cfg.format.type; + tiasm = cfg.format.type; + asm68k = cfg.format.type; + asmh8300 = cfg.format.type; + }; + formatters = + mapListToAttrs (name: { + inherit name; + value = formats.${name}; + }) + cfg.format.type; + }; + }; + }) ]); }