From b56933fe410b7087a0ab215207cff4968c9d745e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 17 Dec 2024 22:53:42 +0100 Subject: [PATCH] nvim/lua/user/plugins/editor/autocomplete.lua: use blink.cmp --- nvim/lua/user/plugins/editor/autocomplete.lua | 126 ++++++------------ 1 file changed, 40 insertions(+), 86 deletions(-) diff --git a/nvim/lua/user/plugins/editor/autocomplete.lua b/nvim/lua/user/plugins/editor/autocomplete.lua index 7646ef0..4f0cd82 100644 --- a/nvim/lua/user/plugins/editor/autocomplete.lua +++ b/nvim/lua/user/plugins/editor/autocomplete.lua @@ -1,92 +1,46 @@ +local icons = require('user.icons') + return { - "hrsh7th/nvim-cmp", - version = false, - event = "InsertEnter", + 'saghen/blink.cmp', + lazy = false, + version = 'v0.*', + build = 'cargo build --release', dependencies = { - "hrsh7th/cmp-buffer", -- autocomplete from buffer - "hrsh7th/cmp-path", -- autocomplete from filesystem - "f3fora/cmp-spell", + { 'L3MON4D3/LuaSnip', version = 'v2.*' }, }, - opts = function() - local cmp = require("cmp") - local utils = require("user.utils.cmp") - local format = require("user.utils.cmp_format") - -- local lspkind = require("user.utils.lspkind") - - local selectPrev = utils.selectPrev({ behavior = cmp.SelectBehavior.Select }) - local selectNext = utils.selectNext({ behavior = cmp.SelectBehavior.Select }) - - return { - preselect = false, - completion = { - completeopt = "menu,menuone,longest,popup", + opts = { + keymap = { preset = 'enter' }, + appearance = { + nerd_font_variant = 'mono', + kind_icons = icons.symbols + }, + sources = { + default = { 'lsp', 'path', 'luasnip', 'buffer' }, + }, + snippets = { + expand = function(snippet) require('luasnip').lsp_expand(snippet) end, + active = function(filter) + if filter and filter.direction then + return require('luasnip').jumpable(filter.direction) + end + return require('luasnip').in_snippet() + end, + jump = function(direction) require('luasnip').jump(direction) end, + }, + completion = { + menu = { + winblend = 5, }, - view = { - entries = { name = "custom", selection_order = "near_cursor" }, + documentation = { + auto_show = true, + window = { + winblend = 5 + } }, - window = { - documentation = { - border = { "", "", "", "", "", "", "", " " }, - }, - completion = { - scrolloff = 4, - }, - }, - mapping = { - [""] = selectPrev, - [""] = selectPrev, - [""] = selectNext, - [""] = selectNext, - [""] = cmp.mapping.abort(), - [""] = utils.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), - }, - -- snippet = { - -- expand = function(args) - -- require("luasnip").lsp_expand(args.body) - -- end, - -- }, - formatting = { - fields = { "kind", "abbr", "menu" }, - format = format({ - symbol_map = require('user.utils.cmp_symbols'), - widths = { - menu = 0, - } - }), - }, - sources = { - { name = "nvim_lsp" }, - { name = 'nvim_lsp_signature_help' }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - { - name = "spell", - keyword_length = 3, - option = { - keep_all_entries = false, - enable_in_context = function() - return require('cmp.config.context').in_treesitter_capture('spell') - end, - preselect_correct_word = true, - }, - }, - }, - experimental = { - ghost_text = { - hl_group = "NonText", - }, - }, - } - end, - config = function(_, opts) - local cmp = require("cmp") - cmp.setup(opts) - - -- insert () on function completion using autopairs - local has_autopair, autopair = pcall(require, "nvim-autopairs.completion.cmp") - if has_autopair then - cmp.event:on("confirm_done", autopair.on_confirm_done()) - end - end, + ghost_text = { + enabled = true, + } + }, + signature = { enabled = true } + } }