summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/blink-cmp.lua
blob: 0c19ef87b7e9d0eeaba3f46c0c331cb8de09ff8c (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
return {
    'saghen/blink.cmp',
    event = 'InsertEnter',
    version = '1.*',
    dependencies = {
        {
            'Kaiser-Yang/blink-cmp-git',
            dependencies = { 'nvim-lua/plenary.nvim' },
        },
    },
    ---@module 'blink.cmp'
    ---@type blink.cmp.Config
    opts = {
        keymap = {
            preset = 'enter',
            ['<C-e>'] = {},
            ['<C-c>'] = { 'hide', 'fallback' },

            ['<C-b>'] = {},
            ['<C-f>'] = {},
            ['<C-u>'] = { 'scroll_documentation_up', 'fallback' },
            ['<C-d>'] = { 'scroll_documentation_down', 'fallback' },
        },

        completion = {
            -- Show documentation when selecting a completion item
            documentation = {
                auto_show = true, -- TODO: turn this to off? once carbonight is ready
                auto_show_delay_ms = 0,
                window = { border = 'single' },
            },

            keyword = { range = 'full' },
            -- Full seems cool but might be annoying
            -- TODO: after a while, did I like this?
            -- If so keep, otherwise switch to prefix

            -- Preselect first one, don't complete until confirmation
            list = { selection = { preselect = true, auto_insert = false } },

            menu = {
                draw = {
                    -- TODO: really cool but ugly AF now
                    -- need to add support for this in carbonight first
                    -- We don't need label_description now because label and label_description are already
                    -- combined together in label by colorful-menu.nvim.
                    -- columns = { { 'kind_icon' }, { 'label', gap = 1 } },
                    -- components = {
                    --     label = {
                    --         text = function(ctx)
                    --             return require('colorful-menu').blink_components_text(ctx)
                    --         end,
                    --         highlight = function(ctx)
                    --             return require('colorful-menu').blink_components_highlight(ctx)
                    --         end,
                    --     },
                    -- },
                },
            },
        },

        -- TODO: configure this when I get to fixing the LSP signature thing
        signature = {},

        fuzzy = { implementation = 'prefer_rust_with_warning' },

        sources = {
            default = { 'lsp', 'path', 'snippets', 'lazydev', 'git' },

            providers = {
                lazydev = {
                    name = 'LazyDev',
                    module = 'lazydev.integrations.blink',
                    score_offset = 100, -- prioritize lazydev
                },
                git = {
                    module = 'blink-cmp-git',
                    name = 'Git',
                    opts = {
                        commit = { triggers = { '~' } },
                    },
                },

                snippets = {
                    score_offset = 200, -- make snippets highest priority
                    transform_items = function(_, items)
                        return vim.tbl_filter(function(item)
                            if item.kind ~= require('blink.cmp.types').CompletionItemKind.Snippet then
                                return true
                            end

                            local name = item.description
                            -- vim.print(name)
                            local parts = vim.split(name, ' ', { trimempty = false })
                            local namespace = #parts > 1 and parts[1] or nil
                            -- vim.print(namespace)
                            if not namespace then
                                return true
                            end

                            -- vim.print(vim.fn.getcwd())
                            local path = vim.split(vim.fn.getcwd(), '/')
                            local dir = path[#path]
                            -- vim.print(dir)

                            return dir == namespace
                        end, items)
                    end,
                },
            },
        },

        appearance = {
            -- TODO: change icons to make more sense to me
            kind_icons = {
                Text = '', --   󰉿
                Method = '󰊕',
                Function = '󰊕',
                Constructor = '󰒓',

                Field = '󰜢',
                Variable = '󰆦',
                Property = '󰖷',

                Class = '󱡠',
                Interface = '󱡠',
                Struct = '󱡠',
                Module = '󰅩',

                Unit = '󰪚',
                Value = '󰦨',
                Enum = '󰦨',
                EnumMember = '󰦨',

                Keyword = '󰻾',
                Constant = '󰏿',

                Snippet = '',
                Color = '󰏘',
                File = '󰈔',
                Reference = '󰬲',
                Folder = '󰉋',
                Event = '󱐋',
                Operator = '󰪚',
                TypeParameter = '󰬛',
            },
        },
    },
    opts_extend = { 'sources.default' },

    -- TODO: pressing backk (deleting), should re-show completion menu
    -- TODO: ghost text only for LLMs?
}