about summary refs log tree commit diff
path: root/fnl/nvrc/packs
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2022-02-26 22:15:29 +0900
committersefidel <contact@sefidel.net>2022-02-26 22:16:42 +0900
commit984feefe0c4de184eed8151260d475c99ac1eeab (patch)
tree0fdcb1525c3221831539e62e2d876ca84f359b83 /fnl/nvrc/packs
parent06695070f47d6ca084d841879e4e39973cce3060 (diff)
downloadnvimrc-984feefe0c4de184eed8151260d475c99ac1eeab.tar.gz
nvimrc-984feefe0c4de184eed8151260d475c99ac1eeab.zip
fix(cmp): fix cmp completion
Diffstat (limited to 'fnl/nvrc/packs')
-rw-r--r--fnl/nvrc/packs/cmp.fnl24
1 files changed, 15 insertions, 9 deletions
diff --git a/fnl/nvrc/packs/cmp.fnl b/fnl/nvrc/packs/cmp.fnl
index 0f36592..0ff8dc2 100644
--- a/fnl/nvrc/packs/cmp.fnl
+++ b/fnl/nvrc/packs/cmp.fnl
@@ -1,5 +1,6 @@
 (import-macros {: set!} :nvrc.macro.set)
 (local cmp (require :cmp))
+(local luasnip (require :luasnip))
 
 (set! completeopt "menuone,noselect")
 
@@ -29,7 +30,8 @@
               :Operator "(op)"
               :TypeParameter "(tp)"})
 
-(cmp.setup {
+(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"
@@ -45,13 +47,17 @@
                       :<C-f> (cmp.mapping.scroll_docs 4)
                       :<C-Space> (cmp.mapping.complete)
                       :<C-e> (cmp.mapping.close)
-                      :<CR> (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace
-                                                  :select true})
-                      :Tab (fn [fallback]
-                             (if (cmp.visible) (cmp.select_next_item)"")
-                             (fallback))
-                      :<S-Tab> (fn [fallback]
-                                 (if (cmp.visible) (cmp.select_next_item)"")
-                                 (fallback))}
+                      :<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}]})