about summary refs log tree commit diff
path: root/fnl/nvrc/packs/conform.fnl
blob: b9e3737ff971857d30b0f40fa57cecfaff0fa5e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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})