summaryrefslogtreecommitdiff
path: root/lua/mo/cmp.lua
blob: be6fb95d6e7d495c01775ae8b2bfb79d15258ab4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
vim.cmd([[ packadd nvim-cmp ]])

local cmp = require("cmp")
local icons = require("mini.icons")
local kinds = require("mo.kinds")
local minisnippets = require("mini.snippets")

cmp.setup({
    view = { entries = "native" },
    formatting = {
        format = function(entry, vim_item)
            if entry.source.name == "nvim_lsp" and vim_item.kind ~= nil then
                local icon, _, _ = icons.get("lsp", vim_item.kind)
                vim_item.kind =
                    string.format("%s %s", icon, kinds[vim_item.kind])
            end
            return vim_item
        end,
    },
    snippet = {
        expand = function(args)
            local insert = minisnippets.config.expand.insert
                or minisnippets.default_insert
            insert({ body = args.body }) -- Insert at cursor
            cmp.resubscribe({ "TextChangedI", "TextChangedP" })
            require("cmp.config").set_onetime({ sources = {} })
        end,
    },
    mapping = cmp.mapping.preset.insert({
        ["<C-b>"] = cmp.mapping.scroll_docs(-4),
        ["<C-f>"] = cmp.mapping.scroll_docs(4),
        ["<C-Space>"] = cmp.mapping.complete(),
        ["<C-e>"] = cmp.mapping.abort(),
        ["<C-y>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    }),
    sources = cmp.config.sources({
        { name = "nvim_lsp" },
    }, {
        { name = "path" },
        { name = "buffer" },
    }),
})