feat: add tabnine

This commit is contained in:
max_richter 2022-07-26 20:32:12 +02:00
parent 4586b3cf71
commit 10e1bca6c0

View File

@ -1,8 +1,17 @@
-- luasnip setup -- luasnip setup
local luasnip = require "luasnip" local luasnip = require "luasnip"
-- local lspkind = require "lspkind" local lspkind = require "lspkind"
local cmp = require "cmp" local cmp = require "cmp"
local cmp_autopairs = require("nvim-autopairs.completion.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') local tabnine = require('cmp_tabnine.config')
tabnine:setup({ 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 = { experimental = {
ghost_text = true 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 = { sources = {
{ name = "nvim_lua" }, { name = "nvim_lua" },
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "cmp_tabnine" },
{ name = "luasnip" }, { name = "luasnip" },
{ name = "path" }, { name = "path" },
{ name = "buffer" }, { name = "buffer" },