2022-04-05 19:57:44 +00:00
|
|
|
(let [cmp (require :cmp)
|
2022-04-15 20:43:51 +00:00
|
|
|
luasnip (require :luasnip)
|
2022-04-05 19:57:44 +00:00
|
|
|
lspkind (require :lspkind)
|
|
|
|
npairs (require :nvim-autopairs.completion.cmp)]
|
|
|
|
(fn has-words-before? []
|
|
|
|
(let [(line col) (-> 0 (vim.api.nvim_win_get_cursor) (unpack))]
|
|
|
|
(if (not= col 0)
|
|
|
|
(let [line-content (vim.api.nvim_buf_get_lines 0 (- line 1) line true)
|
|
|
|
cursor-content (: (. line-content 1) :sub col col)]
|
|
|
|
(= (cursor-content:match "%s") nil))
|
|
|
|
false)))
|
|
|
|
|
|
|
|
(fn map-tab [fallback]
|
|
|
|
(if (cmp.visible) (cmp.select_next_item)
|
2022-04-15 20:43:51 +00:00
|
|
|
(luasnip.expand_or_jumpable) (luasnip.expand_or_jump)
|
2022-04-05 19:57:44 +00:00
|
|
|
(has-words-before?) (cmp.complete)
|
|
|
|
(fallback)))
|
|
|
|
|
|
|
|
(fn map-stab [fallback]
|
|
|
|
(if (cmp.visible) (cmp.select_prev_item)
|
2022-04-15 20:43:51 +00:00
|
|
|
(luasnip.jumpable -1) (luasnip.jump -1)
|
2022-04-05 19:57:44 +00:00
|
|
|
(fallback)))
|
|
|
|
|
|
|
|
(cmp.setup {:sources (cmp.config.sources [{:name :nvim_lsp}
|
2022-04-15 20:43:51 +00:00
|
|
|
{:name :luasnip}
|
2022-04-05 19:57:44 +00:00
|
|
|
{:name :nvim_lua}]
|
|
|
|
[{:name :treesitter}
|
|
|
|
{:name :buffer}
|
|
|
|
{:name :path}])
|
2022-04-14 23:21:13 +00:00
|
|
|
:mapping (cmp.mapping.preset.insert {:<C-e> (cmp.mapping {:i (cmp.mapping.abort)
|
|
|
|
:c (cmp.mapping.close)})
|
|
|
|
:<Tab> (cmp.mapping {:c #(if (cmp.visible)
|
|
|
|
(cmp.select_next_item {:behavior cmp.SelectBehavior.Insert})
|
|
|
|
(cmp.complete))
|
|
|
|
:i map-tab
|
|
|
|
:s map-tab})
|
|
|
|
:<S-Tab> (cmp.mapping {:c #(if (cmp.visible)
|
|
|
|
(cmp.select_prev_item {:behavior cmp.SelectBehavior.Insert})
|
|
|
|
(cmp.complete))
|
|
|
|
:i map-stab
|
|
|
|
:s map-stab})
|
|
|
|
:<C-Space> (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Insert
|
|
|
|
:select true})
|
|
|
|
:<CR> (cmp.mapping.confirm {:select true})})
|
2022-04-05 19:57:44 +00:00
|
|
|
:completion {:keyword_length 2
|
|
|
|
:completeopt "menu,menuone,noinsert"}
|
2022-04-24 18:10:14 +00:00
|
|
|
:window {:documentation (cmp.config.window.bordered {:border :rounded})}
|
2022-04-14 23:21:13 +00:00
|
|
|
:snippet {:expand (fn [args]
|
2022-04-15 20:43:51 +00:00
|
|
|
(luasnip.lsp_expand args.body))}
|
2022-04-24 18:10:14 +00:00
|
|
|
:formatting {:format (lspkind.cmp_format {:mode :symbol_text
|
|
|
|
:menu {:buffer "[Buffer]"
|
|
|
|
:cmdline "[Cmd]"
|
|
|
|
:luasnip "[LuaSnip]"
|
|
|
|
:nvim_lsp "[LSP]"
|
|
|
|
:nvim_lsp_document_symbol "[Symbol]"
|
|
|
|
:nvim_lua "[Lua]"
|
|
|
|
:path "[Path]"
|
|
|
|
:treesitter "[Treesitter]"}})}})
|
2022-04-05 19:57:44 +00:00
|
|
|
(cmp.setup.cmdline "/"
|
|
|
|
{:sources (cmp.config.sources [{:name :nvim_lsp_document_symbol}]
|
2022-04-14 23:21:13 +00:00
|
|
|
[{:name :buffer}])
|
|
|
|
:mapping (cmp.mapping.preset.cmdline)})
|
2022-04-05 19:57:44 +00:00
|
|
|
(cmp.setup.cmdline ":"
|
|
|
|
{:sources (cmp.config.sources [{:name :path}]
|
2022-04-14 23:21:13 +00:00
|
|
|
[{:name :cmdline}])
|
|
|
|
:mapping (cmp.mapping.preset.cmdline)})
|
2022-04-05 19:57:44 +00:00
|
|
|
(cmp.event:on :confirm_done (npairs.on_confirm_done {:map_char {:tex ""}})))
|
2022-04-24 18:10:14 +00:00
|
|
|
|