diff --git a/configs/nvim/lua/configs/autocomplete.lua b/configs/nvim/lua/configs/autocomplete.lua index 4ef0bf8..3cca7c0 100644 --- a/configs/nvim/lua/configs/autocomplete.lua +++ b/configs/nvim/lua/configs/autocomplete.lua @@ -1,8 +1,17 @@ -- luasnip setup local luasnip = require "luasnip" --- local lspkind = require "lspkind" +local lspkind = require "lspkind" local cmp = require "cmp" local cmp_autopairs = require("nvim-autopairs.completion.cmp") +local compare = require('cmp.config.compare') + +local source_mapping = { + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + cmp_tabnine = "[TN]", + path = "[Path]", +} local tabnine = require('cmp_tabnine.config') tabnine:setup({ @@ -33,6 +42,20 @@ cmp.setup { -- } -- ) -- }, + sorting = { + priority_weight = 2, + comparators = { + require('cmp_tabnine.compare'), + compare.offset, + compare.exact, + compare.score, + compare.recently_used, + compare.kind, + compare.sort_text, + compare.length, + compare.order, + }, + }, experimental = { ghost_text = true }, @@ -67,9 +90,24 @@ cmp.setup { } ) }, + formatting = { + format = function(entry, vim_item) + vim_item.kind = lspkind.presets.default[vim_item.kind] + local menu = source_mapping[entry.source.name] + if entry.source.name == 'cmp_tabnine' then + if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then + menu = entry.completion_item.data.detail .. ' ' .. menu + end + vim_item.kind = '' + end + vim_item.menu = menu + return vim_item + end + }, sources = { { name = "nvim_lua" }, { name = "nvim_lsp" }, + { name = "cmp_tabnine" }, { name = "luasnip" }, { name = "path" }, { name = "buffer" },