2024-08-25 23:44:07 -07:00
|
|
|
(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))))
|
|
|
|
|
2024-08-26 23:09:08 -07:00
|
|
|
(let [lspkind (require :lspkind)]
|
2024-08-27 19:18:33 -07:00
|
|
|
(cmp.setup {:formatting {:format (lspkind.cmp_format {:mode "symbol_text"
|
|
|
|
:maxwidth 50})
|
2024-08-26 23:09:08 -07:00
|
|
|
:show_labelDetails true}
|
2024-08-27 19:18:33 -07:00
|
|
|
:snippet {:expand (fn [args] (vim.snippet.expand args.body))}
|
2024-08-25 23:44:07 -07:00
|
|
|
:sources [{:name "buffer"} {:name "nvim_lsp"}
|
|
|
|
{:name "look"} {:name "path"}
|
|
|
|
{:name "calc"} {:name "spell"}
|
|
|
|
{:name "tags"}]
|
|
|
|
:mapping {"<C-d>" (cmp.mapping.scroll_docs -4)
|
|
|
|
"<C-u>" (cmp.mapping.scroll_docs 4)
|
|
|
|
"<C-g>" (cmp.mapping.close)
|
2024-08-27 19:18:33 -07:00
|
|
|
"<CR>" (cmp.mapping.confirm {:select true})
|
|
|
|
"<Tab>" (cmp.mapping (fn [fallback]
|
|
|
|
(if (cmp.visible) (cmp.select_next_item)
|
|
|
|
(has-words-before) (cmp.complete)
|
|
|
|
(fallback)))
|
|
|
|
[:i :s])
|
|
|
|
"<S-Tab>" (cmp.mapping (fn [fallback]
|
|
|
|
(if (cmp.visible) (cmp.select_prev_item)
|
|
|
|
(fallback)))
|
|
|
|
[:i :s])}}))
|