From 811b5ae91117efc586fd7f80c31b236df708768f Mon Sep 17 00:00:00 2001 From: sefidel Date: Wed, 22 May 2024 14:56:47 +0900 Subject: feat(packs): add conform * Replaces LSP-based formatter. No action is needed as the formatter would always fall back to LSP when it's available. --- fnl/nvrc/packs/conform.fnl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 fnl/nvrc/packs/conform.fnl (limited to 'fnl/nvrc/packs/conform.fnl') diff --git a/fnl/nvrc/packs/conform.fnl b/fnl/nvrc/packs/conform.fnl new file mode 100644 index 0000000..b9e3737 --- /dev/null +++ b/fnl/nvrc/packs/conform.fnl @@ -0,0 +1,25 @@ +(import-macros {: set!} :nvrc.macro.set) +(local {: setup :conform-formatexpr formatexpr} (require :conform)) + +(setup {:formatters_by_ft {:nix [:nixpkgs_fmt]}}) + +(set! formatexpr "v:lua.require'conform'.formatexpr({ lsp_fallback = 'always' })") + +(vim.api.nvim_create_user_command :ConformFormat +(fn [args] + (var range nil) + (when (not= args.count (- 1)) + (local end-line + (. (vim.api.nvim_buf_get_lines 0 + (- args.line2 + 1) + args.line2 + true) + 1)) + (set range + {:end [args.line2 (end-line:len)] + :start [args.line1 0]})) + ((. (require :conform) :format) {:async true + :lsp_fallback :always + : range})) +{:range true}) -- cgit 1.4.1