|
| 1 | +local icons = { |
| 2 | + kind = require("modules.utils.icons").get("kind"), |
| 3 | + type = require("modules.utils.icons").get("type"), |
| 4 | + cmp = require("modules.utils.icons").get("cmp"), |
| 5 | +} |
| 6 | +local use_copilot = require("core.settings").use_copilot |
| 7 | + |
| 8 | +local source_labels = { |
| 9 | + copilot = "[CPLT]", |
| 10 | + buffer = "[BUF]", |
| 11 | + lazydev = "[LAZY]", |
| 12 | + lsp = "[LSP]", |
| 13 | + path = "[PATH]", |
| 14 | + ripgrep = "[RG]", |
| 15 | + tmux = "[TMUX]", |
| 16 | + latex_symbols = "[LTEX]", |
| 17 | + snippets = "[SNIP]", |
| 18 | + spell = "[SPELL]", |
| 19 | +} |
| 20 | + |
| 21 | +local sources_default = { "lazydev", "lsp", "snippets", "path", "buffer", "ripgrep", "spell", "tmux", "latex_symbols" } |
| 22 | +if use_copilot then |
| 23 | + table.insert(sources_default, 1, "copilot") |
| 24 | +end |
| 25 | + |
| 26 | +---@module 'blink.cmp' |
| 27 | +---@type blink.cmp.Config |
| 28 | +local opts = { |
| 29 | + snippets = { preset = "luasnip" }, |
| 30 | + cmdline = { |
| 31 | + enabled = true, |
| 32 | + sources = function() |
| 33 | + local type = vim.fn.getcmdtype() |
| 34 | + if type == "/" or type == "?" then |
| 35 | + return { "buffer" } |
| 36 | + end |
| 37 | + if type == ":" or type == "@" then |
| 38 | + return { "cmdline", "path" } |
| 39 | + end |
| 40 | + return {} |
| 41 | + end, |
| 42 | + completion = { |
| 43 | + list = { selection = { preselect = true, auto_insert = true } }, |
| 44 | + menu = { |
| 45 | + auto_show = true, |
| 46 | + draw = { |
| 47 | + columns = { |
| 48 | + { "label", "label_description", gap = 1 }, |
| 49 | + { "kind_icon", "kind", gap = 1 }, |
| 50 | + { "source_name" }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + ghost_text = { enabled = false }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + term = { enabled = false }, |
| 58 | + appearance = { nerd_font_variant = "normal" }, |
| 59 | + fuzzy = { implementation = "prefer_rust_with_warning" }, |
| 60 | + |
| 61 | + sources = { |
| 62 | + default = sources_default, |
| 63 | + providers = { |
| 64 | + lsp = { max_items = 350 }, |
| 65 | + lazydev = { |
| 66 | + module = "lazydev.integrations.blink", |
| 67 | + name = "LazyDev", |
| 68 | + score_offset = 100, |
| 69 | + enabled = function() |
| 70 | + return vim.bo.filetype == "lua" |
| 71 | + end, |
| 72 | + }, |
| 73 | + buffer = { |
| 74 | + opts = { |
| 75 | + get_bufnrs = function() |
| 76 | + return vim.api.nvim_buf_line_count(0) < 15000 and vim.api.nvim_list_bufs() or {} |
| 77 | + end, |
| 78 | + }, |
| 79 | + }, |
| 80 | + ripgrep = { |
| 81 | + module = "blink-ripgrep", |
| 82 | + name = "Ripgrep", |
| 83 | + opts = { |
| 84 | + prefix_min_len = 2, |
| 85 | + backend = { |
| 86 | + use = "ripgrep", |
| 87 | + ripgrep = { |
| 88 | + context_size = 5, |
| 89 | + max_filesize = "1M", |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + score_offset = -15, |
| 94 | + max_items = 3, |
| 95 | + }, |
| 96 | + copilot = { |
| 97 | + name = "Copilot", |
| 98 | + module = "blink-copilot", |
| 99 | + score_offset = 100, |
| 100 | + async = true, |
| 101 | + opts = { |
| 102 | + max_completions = 3, |
| 103 | + max_attempts = 4, |
| 104 | + }, |
| 105 | + }, |
| 106 | + spell = { |
| 107 | + name = "Spell", |
| 108 | + module = "blink.compat.source", |
| 109 | + opts = { cmp_name = "spell" }, |
| 110 | + }, |
| 111 | + tmux = { |
| 112 | + name = "Tmux", |
| 113 | + module = "blink.compat.source", |
| 114 | + opts = { cmp_name = "tmux" }, |
| 115 | + }, |
| 116 | + latex_symbols = { |
| 117 | + name = "LaTeX", |
| 118 | + module = "blink.compat.source", |
| 119 | + opts = { cmp_name = "latex_symbols" }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + |
| 124 | + keymap = { |
| 125 | + preset = "none", |
| 126 | + ["<C-p>"] = { "select_prev", "fallback" }, |
| 127 | + ["<C-n>"] = { "select_next", "fallback" }, |
| 128 | + ["<C-d>"] = { "scroll_documentation_up", "fallback" }, |
| 129 | + ["<C-f>"] = { "scroll_documentation_down", "fallback" }, |
| 130 | + ["<C-w>"] = { "cancel", "fallback" }, |
| 131 | + ["<Tab>"] = { "select_next", "snippet_forward", "fallback" }, |
| 132 | + ["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" }, |
| 133 | + ["<CR>"] = { "accept", "fallback" }, |
| 134 | + }, |
| 135 | + |
| 136 | + completion = { |
| 137 | + keyword = { |
| 138 | + range = "full", |
| 139 | + }, |
| 140 | + accept = { |
| 141 | + auto_brackets = { |
| 142 | + enabled = true, |
| 143 | + kind_resolution = { |
| 144 | + enabled = true, |
| 145 | + }, |
| 146 | + semantic_token_resolution = { |
| 147 | + enabled = true, |
| 148 | + blocked_filetypes = { "java" }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + }, |
| 152 | + ghost_text = { enabled = false }, |
| 153 | + list = { |
| 154 | + max_items = 120, |
| 155 | + selection = { preselect = false, auto_insert = false }, |
| 156 | + }, |
| 157 | + menu = { |
| 158 | + border = "single", |
| 159 | + winhighlight = "Normal:Pmenu,FloatBorder:PmenuBorder,CursorLine:PmenuSel,Search:PmenuSel", |
| 160 | + scrollbar = false, |
| 161 | + draw = { |
| 162 | + padding = { 1, 1 }, |
| 163 | + columns = { |
| 164 | + { "label", "label_description", gap = 1 }, |
| 165 | + { "kind_icon" }, |
| 166 | + { "kind", "source_name", gap = 1 }, |
| 167 | + }, |
| 168 | + components = { |
| 169 | + kind_icon = { |
| 170 | + text = function(ctx) |
| 171 | + local lspkind_icons = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp) |
| 172 | + return icons.cmp[ctx.source_id] or lspkind_icons[ctx.kind] or icons.cmp.undefined |
| 173 | + end, |
| 174 | + }, |
| 175 | + kind = { |
| 176 | + text = function(ctx) |
| 177 | + return ctx.kind or "" |
| 178 | + end, |
| 179 | + highlight = function(ctx) |
| 180 | + return ctx.kind |
| 181 | + end, |
| 182 | + }, |
| 183 | + label = { |
| 184 | + text = function(ctx) |
| 185 | + return require("colorful-menu").blink_components_text(ctx) |
| 186 | + end, |
| 187 | + highlight = function(ctx) |
| 188 | + return require("colorful-menu").blink_components_highlight(ctx) |
| 189 | + end, |
| 190 | + }, |
| 191 | + source_name = { |
| 192 | + text = function(ctx) |
| 193 | + return source_labels[ctx.source_id] or "[BTN]" |
| 194 | + end, |
| 195 | + highlight = "Comment", |
| 196 | + }, |
| 197 | + }, |
| 198 | + }, |
| 199 | + }, |
| 200 | + documentation = { |
| 201 | + auto_show = true, |
| 202 | + auto_show_delay_ms = 200, |
| 203 | + treesitter_highlighting = true, |
| 204 | + window = { |
| 205 | + border = "single", |
| 206 | + winhighlight = "Normal:CmpDoc,FloatBorder:CmpDocBorder", |
| 207 | + }, |
| 208 | + }, |
| 209 | + }, |
| 210 | + signature = { |
| 211 | + enabled = true, |
| 212 | + trigger = { |
| 213 | + show_on_insert = true, |
| 214 | + }, |
| 215 | + window = { |
| 216 | + border = "single", |
| 217 | + treesitter_highlighting = true, |
| 218 | + show_documentation = true, |
| 219 | + }, |
| 220 | + }, |
| 221 | +} |
| 222 | + |
| 223 | +return function() |
| 224 | + require("modules.utils").load_plugin("blink.cmp", opts) |
| 225 | +end |
0 commit comments