helm/home/profiles/nvim/config/fnl/conf/plugins/cmp.fnl
2024-08-25 23:44:07 -07:00

58 lines
2.3 KiB
Fennel

(local cmp (require :cmp))
(fn has-words-before []
(let [(line col) (unpack (vim.api.nvim_win_get_cursor 0))
cur-line (. (vim.api.nvim_buf_get_lines 0
(- line 1)
line
true
1))]
(and (not= col 0)
(= (: (: cur-line :sub col col) :match "%s")
nil))))
(fn tab [fallback]
(let [cmp (require :cmp)
luasnip (require :luasnip)]
(if (cmp.visible)
(cmp.select_next_item)
(let [available (luasnip.expand_or_jumpable)]
(if (= (available) true)
(luasnip.expand_or_jump)
(if (has-words-before)
(cmp.complete)
(fallback)))))))
(fn stab [fallback]
(let [cmp (require :cmp)
luasnip (require :luasnip)]
(if (cmp.visible)
(cmp.select_prev_item)
(let [available (luasnip.jumpable -1)]
(if (= (available) true)
(luasnip.jump -1)
(if (has-words-before)
(cmp.complete)
(fallback)))))))
(let [lspkind (require :lspkind)
luasnip_loaders (require :luasnip.loaders.from_vscode)]
(luasnip_loaders.lazy_load)
(cmp.setup {:formatting {:format lspkind.cmp_format}
:snippet {:expand (fn [args]
(let [luasnip (require :luasnip)]
(luasnip.lsp_expand args.body)))}
:sources [{:name "buffer"} {:name "nvim_lsp"}
{:name "look"} {:name "path"}
{:name "calc"} {:name "spell"}
{:name "cmp-conjure"} {:name "luasnip"}
{:name "tags"}]
:mapping {"<C-d>" (cmp.mapping.scroll_docs -4)
"<C-u>" (cmp.mapping.scroll_docs 4)
"<Up>" (cmp.mapping (cmp.mapping.select_prev_item) [:i :c])
"<Down>" (cmp.mapping (cmp.mapping.select_next_item) [:i :c])
"<C-g>" (cmp.mapping.close)
"<CR>" (cmp.mapping.confirm {:select true})
"<Tab>" (cmp.mapping tab [:i :s])
"<S-Tab>" (cmp.mapping stab [:i :s])}}))