about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2024-05-22 14:56:47 +0900
committersefidel <contact@sefidel.net>2024-05-22 14:56:47 +0900
commit811b5ae91117efc586fd7f80c31b236df708768f (patch)
treeb331d70ee11c9889e248c2a7a7249555c1c046f4
parentc1086f1f88b5335bfd0106264d2b4e5541956620 (diff)
downloadnvimrc-811b5ae91117efc586fd7f80c31b236df708768f.tar.gz
nvimrc-811b5ae91117efc586fd7f80c31b236df708768f.zip
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.
-rw-r--r--fnl/nvrc/keymaps.fnl2
-rw-r--r--fnl/nvrc/pack.fnl1
-rw-r--r--fnl/nvrc/packs/conform.fnl25
-rw-r--r--lazy-lock.json1
4 files changed, 28 insertions, 1 deletions
diff --git a/fnl/nvrc/keymaps.fnl b/fnl/nvrc/keymaps.fnl
index c98a78a..fd74449 100644
--- a/fnl/nvrc/keymaps.fnl
+++ b/fnl/nvrc/keymaps.fnl
@@ -80,7 +80,7 @@
 ; LSP
 (map! [n] :fl (vim.lsp.buf.declaration))
 (map! [n] :fd (vim.lsp.buf.definition))
-(map! [n] :fs (vim.lsp.buf.format))
+(map! [nv :silent] :fs ":ConformFormat<cr>")
 (map! [n] :fa (vim.lsp.buf.code_action))
 (map! [n] :fu (vim.lsp.buf.implementation))
 (map! [n] :fi (vim.lsp.buf.incoming_calls))
diff --git a/fnl/nvrc/pack.fnl b/fnl/nvrc/pack.fnl
index 207d3f6..e041211 100644
--- a/fnl/nvrc/pack.fnl
+++ b/fnl/nvrc/pack.fnl
@@ -44,6 +44,7 @@
                           :dependencies [(pack :lukas-reineke/cmp-under-comparator)
                                          (pack :hrsh7th/cmp-nvim-lsp {:after :nvim-cmp})
                                          (pack :hrsh7th/cmp-nvim-lsp-signature-help)]})
+(pack! :stevearc/conform.nvim {:req :conform :cmd [:ConformInfo :ConformFormat] :keys ["gq"]})
 (pack! :numToStr/Comment.nvim {:init :Comment :lazy true})
 (pack! :ibhagwan/fzf-lua {:req :fzf :lazy true})
 (pack! :ggandor/leap.nvim {:req :leap :keys [:s :S]})
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})
diff --git a/lazy-lock.json b/lazy-lock.json
index 8ffae9c..91b772f 100644
--- a/lazy-lock.json
+++ b/lazy-lock.json
@@ -4,6 +4,7 @@
   "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
   "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "3d8912ebeb56e5ae08ef0906e3a54de1c66b92f1" },
   "cmp-under-comparator": { "branch": "master", "commit": "6857f10272c3cfe930cece2afa2406e1385bfef8" },
+  "conform.nvim": { "branch": "master", "commit": "00f9d91391b04b1935e2f15948bd96cc111e7d3a" },
   "editorconfig.nvim": { "branch": "master", "commit": "5b9e303e1d6f7abfe616ce4cc8d3fffc554790bf" },
   "fzf-lua": { "branch": "main", "commit": "64f6eff4702c23c4de5320ed668343af1e4d679e" },
   "fidget.nvim": { "branch": "main", "commit": "1ba38e4cbb24683973e00c2e36f53ae64da38ef5" },