about summary refs log tree commit diff
path: root/fnl/nvrc/packs/cmp.fnl
blob: 616a39ddc36b94aa10da4b171a67d112a3a8e884 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(import-macros {: set!} :nvrc.macro.set)
(local cmp (require :cmp))
(local luasnip (require :luasnip))

(set! completeopt "menuone,noselect")

(local icons {:Text "(t)"
              :Method "(m)"
              :Function "(f)"
              :Constructor "(cs)"
              :Field "(s)"
              :Variable "(v)"
              :Class "(c)"
              :Interface "(i)"
              :Module "(m)"
              :Property "(p)"
              :Unit "(u)"
              :Value "(v)"
              :Enum "(e)"
              :Keyword "(k)"
              :Snippet "(sn)"
              :Color "(co)"
              :File "(fi)"
              :Reference "(r)"
              :Folder "(fl)"
              :EnumMember "(em)"
              :Constant "(cn)"
              :Struct "(s)"
              :Event "(ev)"
              :Operator "(op)"
              :TypeParameter "(tp)"})

(cmp.setup {:snippet {:expand (fn [args]
                                ((. (require :luasnip) :lsp_expand) args.body))}
            :formatting {:format (fn [entry vim-item]
                                   (set vim-item.kind
                                        (string.format "%s %s"
                                                       (. icons vim-item.kind)
                                                       vim-item.kind))
                                   (set vim-item.menu
                                        (. {:nvim_lsp "[LSP]"}
                                           entry.source.name))
                                   vim-item)}
            :mapping {:<C-p> (cmp.mapping.select_prev_item)
                      :<C-n> (cmp.mapping.select_next_item)
                      :<C-d> (cmp.mapping.scroll_docs (- 4))
                      :<C-f> (cmp.mapping.scroll_docs 4)
                      :<C-Space> (cmp.mapping.complete)
                      :<C-e> (cmp.mapping.close)
                      :<CR> (cmp.mapping (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace
                                                               :select false}) [:i :c])
                      :<Tab> (cmp.mapping {:i (fn [fallback]
                                              (if (cmp.visible) (cmp.select_next_item)
                                              (luasnip.expand_or_jumpable) (luasnip.expand_or_jump)
                                              (fallback)))
                                         :c (cmp.mapping.select_prev_item {:select true})})
                      :<S-Tab> (cmp.mapping {:i (fn [fallback]
                                                  (if (cmp.visible) (cmp.select_next_item)
                                                  (luasnip.jumpable -1) (luasnip.jump -1)
                                                  (fallback)))
                                             :c (cmp.mapping.select_prev_item {:select true})})}
            :sources [{:name :nvim_lsp}
                      {:name :nvim_lsp_signature_help}]})