aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/nvim-cmp.lua
blob: d95d0bc2e9fbe4a6ab4b71dc587b123864daee9d (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
return {
    "hrsh7th/nvim-cmp",
    opts = function()
        vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
        local cmp = require "cmp"
        local defaults = require "cmp.config.default"()
        return {
            enabled = function()
                local context = require "cmp.config.context"
                if vim.api.nvim_get_mode().mode == "c" then
                    return true
                else
                    return not context.in_treesitter_capture "comment" and not context.in_syntax_group "Comment"
                end
            end,

            completion = {
                completeopt = "menu,menuone,noinsert",
            },
            snippet = {
                expand = function(args)
                    require("luasnip").lsp_expand(args.body)
                end,
            },
            window = {
                completion = cmp.config.window.bordered(),
                documentation = cmp.config.window.bordered(),
            },
            mapping = cmp.mapping.preset.insert {
                ["<C-j>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
                ["<C-k>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
                ["<C-b>"] = cmp.mapping.scroll_docs(-4),
                ["<C-f>"] = cmp.mapping.scroll_docs(4),
                ["<S-CR>"] = cmp.mapping.abort(),
                ["<CR>"] = cmp.mapping.confirm { select = false },
            },
            sources = cmp.config.sources {
                { name = "nvim_lsp" },
                { name = "path" },
            },
            formatting = {
                format = function(_, item)
                    local icons = require("icons").kinds
                    if icons[item.kind] then
                        item.kind = icons[item.kind] .. item.kind
                    end
                    return item
                end,
            },
            experimental = {
                ghost_text = {
                    hl_group = "CmpGhostText",
                },
            },
            sorting = defaults.sorting,
        }
    end,
    dependencies = {
        { "L3MON4D3/LuaSnip", build = "make install_jsregexp" },
        "hrsh7th/cmp-path",
        "saadparwaiz1/cmp_luasnip",
    },
    enabled = false,
}