about summary refs log tree commit diff
path: root/fnl/nvrc/packs/cmp.fnl
blob: b49a1c86579d7076b8f27c9f7eb0446cb9b86c6c (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(import-macros {: set!} :nvrc.macro.set)
(local {: setup
        : mapping
        :config {: compare : disable}
        : ConfirmBehavior
        : visible
        : select_next_item
        : select_prev_item} (require :cmp))
(local under-compare (require :cmp-under-comparator))
(local clangd-score (require :clangd_extensions.cmp_scores))
(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)"})

(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> (mapping.select_prev_item)
                      :<C-n> (mapping.select_next_item)
                      :<C-d> (mapping.scroll_docs (- 4))
                      :<C-f> (mapping.scroll_docs 4)
                      :<C-Space> (mapping.complete)
                      :<C-e> (mapping.close)
                      :<up> disable
                      :<down> disable
                      :<CR> (mapping (mapping.confirm {:behavior ConfirmBehavior.Replace
                                                               :select false}) [:i :c])
                      :<Tab> (mapping {:i (fn [fallback]
                                              (if (visible) (select_next_item)
                                              (luasnip.expand_or_jumpable) (luasnip.expand_or_jump)
                                              (fallback)))})
                      :<S-Tab> (mapping {:i (fn [fallback]
                                                  (if (visible) (select_next_item)
                                                  (luasnip.jumpable -1) (luasnip.jump -1)
                                                  (fallback)))})}
            :sources [{:name :nvim_lsp}
                      {:name :nvim_lsp_signature_help}]
            :sorting {:comparators [compare.offset
                                    compare.exact
                                    clangd-score
                                    compare.score
                                    under-compare.under
                                    compare.kind
                                    compare.sort_text
                                    compare.length
                                    compare.order]}})