about summary refs log tree commit diff
path: root/fnl/nvrc
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2022-02-27 16:20:25 +0900
committersefidel <contact@sefidel.net>2022-02-27 16:20:25 +0900
commita1b5c128220b6fbac345db898f74f8b052e8dd63 (patch)
tree39583c737b12c7673ac56f7881554e1c2dc9a014 /fnl/nvrc
parent4881bb0aa5736be203db26aa9e3fcc7bdae8e2fb (diff)
downloadnvimrc-a1b5c128220b6fbac345db898f74f8b052e8dd63.tar.gz
nvimrc-a1b5c128220b6fbac345db898f74f8b052e8dd63.zip
feat(cmp): destructure require & use custom comparators
Diffstat (limited to 'fnl/nvrc')
-rw-r--r--fnl/nvrc/pack.fnl3
-rw-r--r--fnl/nvrc/packs/cmp.fnl49
2 files changed, 35 insertions, 17 deletions
diff --git a/fnl/nvrc/pack.fnl b/fnl/nvrc/pack.fnl
index fd13659..9df353b 100644
--- a/fnl/nvrc/pack.fnl
+++ b/fnl/nvrc/pack.fnl
@@ -28,7 +28,8 @@
 (pack! :stefandtw/quickfix-reflector.vim {:ft :qf})
 
 (pack! :L3MON4D3/LuaSnip {:module :luasnip})
-(pack! :hrsh7th/nvim-cmp {:req :cmp :event :InsertEnter})
+(pack! :hrsh7th/nvim-cmp {:req :cmp :event :InsertEnter
+                          :requires [(pack :lukas-reineke/cmp-under-comparator {:module :cmp-under-comparator})]})
 (pack! :numToStr/Comment.nvim {:module :Comment :init :Comment})
 (pack! :ibhagwan/fzf-lua {:req :fzf :module :fzf-lua})
 (pack! :ggandor/lightspeed.nvim)
diff --git a/fnl/nvrc/packs/cmp.fnl b/fnl/nvrc/packs/cmp.fnl
index 616a39d..7e88eea 100644
--- a/fnl/nvrc/packs/cmp.fnl
+++ b/fnl/nvrc/packs/cmp.fnl
@@ -1,5 +1,12 @@
 (import-macros {: set!} :nvrc.macro.set)
-(local cmp (require :cmp))
+(local {: setup
+        : mapping
+        :config {: compare : disable}
+        : ConfirmBehavior
+        : visible
+        : select_next_item
+        : select_prev_item} (require :cmp))
+(local under-compare (require :cmp-under-comparator))
 (local luasnip (require :luasnip))
 
 (set! completeopt "menuone,noselect")
@@ -30,7 +37,7 @@
               :Operator "(op)"
               :TypeParameter "(tp)"})
 
-(cmp.setup {:snippet {:expand (fn [args]
+(setup {:snippet {:expand (fn [args]
                                 ((. (require :luasnip) :lsp_expand) args.body))}
             :formatting {:format (fn [entry vim-item]
                                    (set vim-item.kind
@@ -41,23 +48,33 @@
                                         (. {: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
+            :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> (cmp.mapping {:i (fn [fallback]
-                                              (if (cmp.visible) (cmp.select_next_item)
+                      :<Tab> (mapping {:i (fn [fallback]
+                                              (if (visible) (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)
+                                         :c (mapping.select_prev_item {:select true})})
+                      :<S-Tab> (mapping {:i (fn [fallback]
+                                                  (if (visible) (select_next_item)
                                                   (luasnip.jumpable -1) (luasnip.jump -1)
                                                   (fallback)))
-                                             :c (cmp.mapping.select_prev_item {:select true})})}
+                                             :c (mapping.select_prev_item {:select true})})}
             :sources [{:name :nvim_lsp}
-                      {:name :nvim_lsp_signature_help}]})
+                      {:name :nvim_lsp_signature_help}]
+            :sorting {:comparators [compare.offset
+                                    compare.exact
+                                    compare.score
+                                    under-compare.under
+                                    compare.kind
+                                    compare.sort_text
+                                    compare.length
+                                    compare.order]}})