|
| 1 | +local icons = require("chrishrb.config.icons") |
| 2 | + |
| 3 | +local has_copilot = pcall(require, "blink-cmp-copilot") |
| 4 | + |
| 5 | +local sources_default = { "lsp", "buffer", "path", "git" } |
| 6 | +if has_copilot then |
| 7 | + table.insert(sources_default, 1, "copilot") |
| 8 | +end |
| 9 | + |
| 10 | +local providers = { |
| 11 | + lsp = { |
| 12 | + name = "LSP", |
| 13 | + module = "blink.cmp.sources.lsp", |
| 14 | + }, |
| 15 | + buffer = { |
| 16 | + name = "Buffer", |
| 17 | + module = "blink.cmp.sources.buffer", |
| 18 | + }, |
| 19 | + path = { |
| 20 | + name = "Path", |
| 21 | + module = "blink.cmp.sources.path", |
| 22 | + }, |
| 23 | + git = { |
| 24 | + name = "Git", |
| 25 | + module = "blink-cmp-git", |
| 26 | + }, |
| 27 | +} |
| 28 | + |
| 29 | +if has_copilot then |
| 30 | + providers.copilot = { |
| 31 | + name = "Copilot", |
| 32 | + module = "blink-cmp-copilot", |
| 33 | + score_offset = 100, |
| 34 | + async = true, |
| 35 | + } |
| 36 | +end |
| 37 | + |
| 38 | +require("blink.cmp").setup({ |
| 39 | + keymap = { |
| 40 | + ["<C-k>"] = { "select_prev", "fallback" }, |
| 41 | + ["<C-j>"] = { "select_next", "fallback" }, |
| 42 | + ["<C-b>"] = { "scroll_documentation_up", "fallback" }, |
| 43 | + ["<C-f>"] = { "scroll_documentation_down", "fallback" }, |
| 44 | + ["<C-Space>"] = { "show" }, |
| 45 | + ["<C-e>"] = { "cancel", "fallback" }, |
| 46 | + ["<CR>"] = { "accept", "fallback" }, |
| 47 | + ["<Tab>"] = { "select_next", "fallback" }, |
| 48 | + ["<S-Tab>"] = { "select_prev", "fallback" }, |
| 49 | + }, |
| 50 | + cmdline = { |
| 51 | + keymap = { |
| 52 | + preset = "inherit", |
| 53 | + |
| 54 | + ["<Tab>"] = { "show_and_insert_or_accept_single", "select_next" }, |
| 55 | + ["<S-Tab>"] = { "show_and_insert_or_accept_single", "select_prev" }, |
| 56 | + }, |
| 57 | + completion = { menu = { auto_show = false } }, |
| 58 | + }, |
| 59 | + completion = { |
| 60 | + menu = { |
| 61 | + draw = { |
| 62 | + columns = { { "kind_icon" }, { "label", gap = 1 }, { "source_name" } }, |
| 63 | + components = { |
| 64 | + kind_icon = { |
| 65 | + text = function(ctx) |
| 66 | + return (icons.kind[ctx.kind] or icons.kind.Fallback) .. " " |
| 67 | + end, |
| 68 | + }, |
| 69 | + source_name = { |
| 70 | + text = function(ctx) |
| 71 | + local labels = { |
| 72 | + LSP = "[LSP]", |
| 73 | + Copilot = "[Copilot]", |
| 74 | + AI = "[AI]", |
| 75 | + Buffer = "[Buffer]", |
| 76 | + Path = "[Path]", |
| 77 | + Git = "[Git]", |
| 78 | + } |
| 79 | + return labels[ctx.source_name] or ("[" .. ctx.source_name .. "]") |
| 80 | + end, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + documentation = { |
| 86 | + auto_show = true, |
| 87 | + auto_show_delay_ms = 0, |
| 88 | + window = { |
| 89 | + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + sources = { |
| 94 | + default = sources_default, |
| 95 | + providers = providers, |
| 96 | + }, |
| 97 | +}) |
0 commit comments