Browse Source

feat(neovim): improve completion with `blink.cmp`

Joe 2 months ago
parent
commit
95c9603f98

+ 20 - 0
.config/nvim/custom/jonathandarker/lua/jonathandarker/colors/plugins/blink.lua

@@ -0,0 +1,20 @@
+return {
+    load = function(p)
+        p.hset("BlinkCmpMenu", { fg = p.FOREGROUND, bg = p.BACKGROUND })
+        p.hset("BlinkCmpDoc", { fg = p.FOREGROUND, bg = p.BACKGROUND })
+        p.hset("BlinkCmpMenuBorder", { fg = p.GREY, bg = p.BACKGROUND })
+        p.hset("BlinkCmpDocBorder", { fg = p.GREY, bg = p.BACKGROUND })
+        p.hset("BlinkCmpMenuSelection", { fg = p.BACKGROUND, bg = p.ORANGE, bold = true })
+
+        local kinds = {
+            "Class", "Color", "Constant", "Constructor", "Enum", "EnumMember",
+            "Event", "Field", "File", "Folder", "Function", "Interface", "Keyword",
+            "Method", "Module", "Operator", "Property", "Reference", "Snippet",
+            "Struct", "Text", "TypeParameter", "Unit", "Value", "Variable"
+        }
+
+        for _, kind in ipairs(kinds) do
+            p.hset("BlinkCmpKind" .. kind, { fg = p.ORANGE })
+        end
+    end
+}

+ 1 - 0
.config/nvim/custom/jonathandarker/lua/jonathandarker/colors/plugins/init.lua

@@ -12,5 +12,6 @@ return {
         require("jonathandarker.colors.plugins.status-beast").load(p)
         require("jonathandarker.colors.plugins.jxdash").load(p)
         require("jonathandarker.colors.plugins.render-markdown-nvim").load(p)
+        require("jonathandarker.colors.plugins.blink").load(p)
     end
 }

+ 61 - 67
.config/nvim/init.lua

@@ -143,14 +143,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
 -- === === === === === === === === === === === === === === === === === === ===
 
 vim.pack.add({
-    "https://github.com/hrsh7th/cmp-buffer",
-    "https://github.com/hrsh7th/cmp-calc",
-    "https://github.com/hrsh7th/cmp-cmdline",
-    "https://github.com/hrsh7th/cmp-nvim-lsp",
-    "https://github.com/hrsh7th/cmp-nvim-lsp-signature-help",
-    "https://github.com/hrsh7th/cmp-nvim-lua",
-    "https://github.com/hrsh7th/cmp-path",
-    "https://github.com/hrsh7th/nvim-cmp",
     "https://github.com/kylechui/nvim-surround",
     "https://github.com/lewis6991/gitsigns.nvim",
     "https://github.com/lukas-reineke/virt-column.nvim",
@@ -158,10 +150,11 @@ vim.pack.add({
     "https://github.com/nvim-telescope/telescope-file-browser.nvim",
     "https://github.com/nvim-telescope/telescope-ui-select.nvim",
     "https://github.com/nvim-telescope/telescope.nvim",
-    "https://github.com/nvim-treesitter/nvim-treesitter",
     "https://github.com/nvim-treesitter/nvim-treesitter-context",
-    "https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
+    { src = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects", version = "master" },
+    { src = "https://github.com/nvim-treesitter/nvim-treesitter",             version = "master" },
     "https://github.com/stevearc/aerial.nvim",
+    "https://github.com/saghen/blink.cmp",
     "https://github.com/tpope/vim-commentary"
 })
 
@@ -288,61 +281,62 @@ local function config_pandoctrinated()
     })
 end
 
-local function config_nvim_cmp()
-    local cmp = require("cmp")
-    local mapping = {
-        ["<Tab>"] = function(fallback)
-            if cmp.visible() then
-                cmp.select_next_item(
-                    { behavior = cmp.SelectBehavior.Select })
-            else
-                fallback()
-            end
-        end,
-        ["<S-Tab>"] = function(fallback)
-            if cmp.visible() then
-                cmp.select_prev_item(
-                    { behavior = cmp.SelectBehavior.Select })
-            else
-                fallback()
-            end
-        end,
-        ["<CR>"] = function(fallback)
-            if cmp.visible() and cmp.get_active_entry() then
-                cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace })
-            else
-                fallback()
-            end
-        end
-    }
-    cmp.setup({
-        snippet = {},
-        mapping = mapping,
-        sources = cmp.config.sources({ { name = "nvim_lsp" } }, {
-            { name = "buffer" }, { name = "nvim_lua" }, { name = "calc" },
-            { name = "nvim_lsp_signature_help" }, { name = "path" }
-        })
-    })
-    cmp.setup.cmdline("/", {
-        mapping = cmp.mapping.preset.cmdline(),
-        sources = { { name = "buffer" } }
-    })
-    cmp.setup.cmdline(":", {
-        mapping = cmp.mapping.preset.cmdline(),
-        sources = cmp.config.sources({ { name = "path" } }, {
-            { name = "cmdline", option = { ignore_cmds = { "Man", "!" } } }
-        })
-    })
-
-    vim.api.nvim_create_autocmd("LspAttach", {
-        callback = function(args)
-            local client = vim.lsp.get_client_by_id(args.data.client_id)
-            if client == nil then return end
-            if client:supports_method('textDocument/completion') then
-                vim.lsp.completion.enable(true, client.id, args.buf,
-                    { autotrigger = false })
-            end
-        end
+local function config_blink_cmp()
+    local blink = require("blink.cmp")
+    blink.setup({
+        keymap = {
+            preset = 'none',
+            ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
+            ['<C-e>'] = { 'hide' },
+            ['<C-y>'] = { 'select_and_accept' },
+            ['<Tab>'] = { 'select_next', 'snippet_forward', 'fallback' },
+            ['<S-Tab>'] = { 'select_prev', 'snippet_backward', 'fallback' },
+            ['<CR>'] = { 'accept', 'fallback' },
+            ['<C-p>'] = { 'scroll_documentation_up', 'fallback' },
+            ['<C-n>'] = { 'scroll_documentation_down', 'fallback' },
+        },
+        completion = {
+            list = {
+                selection = {
+                    preselect = false,
+                    auto_insert = false
+                }
+            },
+            menu = {
+                draw = {
+                    columns = { { "kind_icon" }, { "label", "label_description", gap = 1 } },
+                },
+                border = { "⌌", "-", "⌍", "¦", "⌏", "-", "⌎", "¦" }
+            },
+            documentation = {
+                auto_show = true,
+                auto_show_delay_ms = 200,
+                window = {
+                    border = { "⌌", "-", "⌍", "¦", "⌏", "-", "⌎", "¦" }
+                }
+            },
+        },
+        appearance = {
+            use_nvim_cmp_as_default = true,
+            nerd_font_variant = 'mono',
+        },
+        fuzzy = { implementation = "prefer_rust", prebuilt_binaries = { download = true, force_version = "v1.8.0" } },
+        sources = {
+            default = { 'lsp', 'path', 'snippets', 'buffer' },
+            providers = {
+                lsp = { score_offset = 100 },
+                buffer = { score_offset = 0 },
+            }
+        },
+        signature = { enabled = true },
+        cmdline = {
+            enabled = true,
+            keymap = {
+                ['<Tab>'] = { 'show', 'select_next', 'fallback' },
+                ['<S-Tab>'] = { 'select_prev', 'fallback' },
+                ['<CR>'] = { 'accept', 'fallback' },
+            }
+        },
     })
 end
 
@@ -585,7 +579,7 @@ local function config_status_beast()
         {
             group = vim.api.nvim_create_augroup('StatusBeast',
                 { clear = true }),
-            callback = function (args)
+            callback = function(args)
                 if vim.bo[args.buf].filetype == "aerial" then
                     return
                 end
@@ -908,7 +902,7 @@ local setup_plugins = function()
     config_virt_column()
     config_nvim_surround()
     config_like_a_butterfly()
-    config_nvim_cmp()
+    config_blink_cmp()
     config_telescope()
     config_jxdash()
     config_nvim_treesitter_textobjects()