From a1b5c128220b6fbac345db898f74f8b052e8dd63 Mon Sep 17 00:00:00 2001 From: sefidel Date: Sun, 27 Feb 2022 16:20:25 +0900 Subject: feat(cmp): destructure require & use custom comparators --- fnl/nvrc/pack.fnl | 3 ++- fnl/nvrc/packs/cmp.fnl | 49 +++++++++++++++++++++++++++++++++---------------- 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 {: (cmp.mapping.select_prev_item) - : (cmp.mapping.select_next_item) - : (cmp.mapping.scroll_docs (- 4)) - : (cmp.mapping.scroll_docs 4) - : (cmp.mapping.complete) - : (cmp.mapping.close) - : (cmp.mapping (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace + :mapping {: (mapping.select_prev_item) + : (mapping.select_next_item) + : (mapping.scroll_docs (- 4)) + : (mapping.scroll_docs 4) + : (mapping.complete) + : (mapping.close) + : disable + : disable + : (mapping (mapping.confirm {:behavior ConfirmBehavior.Replace :select false}) [:i :c]) - : (cmp.mapping {:i (fn [fallback] - (if (cmp.visible) (cmp.select_next_item) + : (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})}) - : (cmp.mapping {:i (fn [fallback] - (if (cmp.visible) (cmp.select_next_item) + :c (mapping.select_prev_item {:select true})}) + : (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]}}) -- cgit 1.4.1