0

This are the installation instructions for tzachar/cmp-tabnine using Packer:

return require("packer").startup(
 function(use)
    use "hrsh7th/nvim-cmp" --completion
    use {'tzachar/cmp-tabnine', run='./install.sh', requires = 'hrsh7th/nvim-cmp'}
 end
)

And later, enable the plugin:

require'cmp'.setup {
 sources = {
    { name = 'cmp_tabnine' },
 },
}

There is also some setup.

This is the NvChad documentation for adding a plugin, and for overriding default plugin configuration.

This is what I've done:

-- NvChad/lua/custom/plugins/init.lua
return {
   ["tzachar/cmp-tabnine"] = {
      after = "cmp-path",
      config = function()
         require "custom.plugins.tabnine"
      end,
   },
}

-- NvChad/lua/custom/plugins/tabnine.lua
require('cmp_tabnine.config').setup({
   max_lines = 1000;
   max_num_results = 20;
   sort = true;
   run_on_every_keystroke = true;
   snippet_placeholder = '..';
   ignored_file_types = { -- default is not to ignore
           -- uncomment to ignore in lua:
           -- lua = true
   };
   show_prediction_strength = false;
})

-- NvChad/lua/custom/chardrc.lua
M.plugins = {
   override = {
      ["hrsh7th/nvim-cmp"] = {
         sources = {
            { name = "nvim_lsp" },
            { name = "luasnip" },
            { name = "buffer" },
            { name = "nvim_lua" },
            { name = "path" },
            { name = "cmp-tabnine" },
          },
      }
   }
}

There must be something I'm doing wrong. When I do :PackerSync nothing happens.

The developer of cmp-tabnine tzachar has said:

Never used NvChad. But one issue that comes to mind is that you need to run the install.sh script. No Idea how to do that in NvChad.

Here is an example configuration in NvChad.

3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    May 15, 2022 at 13:52
  • Welcome to Vi and Vim! This type of problem may be best answered by asking the plugin devs and/or community directly.
    – D. Ben Knoble
    May 16, 2022 at 15:20
  • cmp-tabnine should be cmp_tabnine and you also need to add custom formatting.
    – Asher
    Aug 10, 2022 at 8:17

1 Answer 1

3

I've got tabnine working with my local nvchad version. Here's what I added to my custom configuration.

lua/custom/chardrc.lua

local pluginConfs = require "custom.plugins.configs"
local M = {}

M.plugins = {
  user = require "custom.plugins",
  override = {
    ["hrsh7th/nvim-cmp"] = pluginConfs.cmp,
    ["tzachar/cmp-tabnine"] = pluginConfs.tabnine
  }
}

lua/custom/plugins/configs.lua

local M = {}

M.cmp = function()
  return {
    formatting = {
      format = function(entry, vim_item)
        if entry.source.name == 'cmp_tabnine' and entry.completion_item.data ~= nil then
            vim_item.kind = string.format("%s %s", '', ' TabNine')
        else
          local icons = require("nvchad_ui.icons").lspkind
          vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
        end

        return vim_item
      end,
    },
    sources = {
      { name = "cmp_tabnine" },
      { name = "luasnip" },
      { name = "nvim_lsp" },
      { name = "buffer" },
      { name = "nvim_lua" },
      { name = "path" },
    },
  }
end

M.tabnine = function()
  return {
    max_lines = 1000,
    max_num_results = 5,
    sort = true,
    run_on_every_keystroke = true,
    show_prediction_strength = false
  }
end

return M

lua/custom/plugins/init.lua

-- custom/plugins/init.lua has to return a table
-- THe plugin name is github user or organization name/reponame
local pluginConfs = require "custom.plugins.configs"

return {
  ["tzachar/cmp-tabnine"] = {
     after = "nvim-cmp",
     run = "./install.sh",
     config = pluginConfs.tabnine
  },
}
2
  • 1
    Sadly, I think the OP is not around anymore to vote on/comment on/accept this answer, so have my upvote :)
    – D. Ben Knoble
    Aug 10, 2022 at 16:57
  • ty! I hit this page while I was trying to get it working. Hopefully, it'll help others. :D
    – Asher
    Aug 13, 2022 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.