about summary refs log tree commit diff
path: root/fnl/nvrc/packs/cmp.fnl
blob: 6fea0d1e7f014c18e645effe75346e46aacba975 (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
(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))

(set! completeopt "menuone,noselect")

(local icons {:Text "(t)"
              :Method "(m)"
              :Function "(f)"
              :Constructor "(C)"
              :Field "(s)"
              :Variable "(v)"
              :Class "(C)"
              :Interface "(i)"
              :Module "(m)"
              :Property "(p)"
              :Unit "(u)"
              :Value "(v)"
              :Enum "(e)"
              :EnumMember "(e)"
              :Keyword "(k)"
              :Snippet "(S)"
              :Color "(R)"
              :Reference "(r)"
              :Constant "(c)"
              :Struct "(s)"
              :Event "(e)"
              :Operator "(o)"
              :TypeParameter "(T)"
              :File "(F)"
              :Folder "(F)"
              })

(setup {:snippet {:expand (fn [args]
                                (vim.snippet.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)
                                              (vim.snippet.active {:direction 1}) (vim.snippet.jump 1)
                                              (fallback)))})
                      :<S-Tab> (mapping {:i (fn [fallback]
                                                  (if (visible) (select_next_item)
                                                  (vim.snippet.active {:direction -1}) (vim.snippet.jump -1)
                                                  (fallback)))})}
            :sources [{:name :nvim_lsp}]
            :sorting {:comparators [compare.offset
                                    compare.exact
                                    clangd-score
                                    compare.score
                                    under-compare.under
                                    compare.kind
                                    compare.sort_text
                                    compare.length
                                    compare.order]}})