tzachar / cmp-tabnine

TabNine plugin for hrsh7th/nvim-cmp
MIT License
287 stars 28 forks source link

Tabnine completes in prompt buffers #5

Closed brandoncc closed 3 years ago

brandoncc commented 3 years ago

Hello, and thank you for this plugin.

cmp disables itself in buftype=prompt buffers, but this plugin doesn't seem to respect that for some reason. I use https://github.com/nvim-telescope/telescope.nvim and cmp-tabnine offers completions in the telescope prompt buffer. Do you have any idea why this might be happening?

" Setup global configuration. More on configuration below.
lua <<EOF
  local cmp = require('cmp')

  -- For Tab, S-Tab, and C-Space bindings that came from
  -- https://github.com/quangnguyen30192/cmp-nvim-ultisnips
  local t = function(str)
    return vim.api.nvim_replace_termcodes(str, true, true, true)
  end

  cmp.setup {
    snippet = {
      expand = function(args)
        vim.fn["UltiSnips#Anon"](args.body)
      end,
    },

    -- You must set mapping if you want.
    mapping = {
      ['<C-p>'] = cmp.mapping.select_prev_item(),
      ['<C-n>'] = cmp.mapping.select_next_item(),
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
      ['<CR>'] = cmp.mapping.confirm({
        behavior = cmp.ConfirmBehavior.Replace,
        select = false,
      }),

      ["<C-Space>"] = cmp.mapping(function(fallback)
        if vim.fn.pumvisible() == 1 then
          if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
            return vim.fn.feedkeys(t("<C-R>=UltiSnips#ExpandSnippet()<CR>"))
          end

          vim.fn.feedkeys(t("<C-n>"), "n")
        else
          fallback()
        end
      end, {
        "i",
        "s",
      }),
      ["<Tab>"] = cmp.mapping(function(fallback)
        if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
          vim.fn.feedkeys(t("<C-R>=UltiSnips#JumpForwards()<CR>"))
        elseif vim.fn.pumvisible() == 1 then
          vim.fn.feedkeys(t("<C-n>"), "n")
        else
          fallback()
        end
      end, {
        "i",
        "s",
      }),
      ["<S-Tab>"] = cmp.mapping(function(fallback)
        if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then
          return vim.fn.feedkeys(t("<C-R>=UltiSnips#JumpBackwards()<CR>"))
        elseif vim.fn.pumvisible() == 1 then
          vim.fn.feedkeys(t("<C-p>"), "n")
        else
          fallback()
        end
      end, {
        "i",
        "s",
      }),
    },

    -- You should specify your *installed* sources.
    sources = {
      { name = 'buffer' },
      { name = 'nvim_lsp' },
      { name = 'cmp_tabnine' },
      { name = 'path' },
      { name = 'calc' },
      { name = 'ultisnips' }
    },
  }

  local tabnine = require('cmp_tabnine.config')
  tabnine:setup({
    max_lines = 1000;
    max_num_results = 20;
    sort = true;
  })
EOF

" Setup buffer configuration (nvim-lua source only enables in Lua filetype).
autocmd FileType lua lua require'cmp'.setup.buffer {
\   sources = {
\     { name = 'buffer' },
\     { name = 'nvim_lua' },
\   },
\ }
tzachar commented 3 years ago

No idea. I suggest you open an issue with nvim-cmp, as cmp-tabnin cannot operate on its own, but only supplies completion entries to nvim-cmp.

brandoncc commented 3 years ago

I received basically the same response about it there, saying maybe it was cmp-tabnine causing it 😂

tzachar commented 3 years ago

Can you link to the issue there? And can you try to capture a short screengrab to show the issue?

tzachar commented 3 years ago

nvim-cmp update its documentation. You can try the following: autocmd FileType TelescopePrompt lua require('cmp').setup.buffer { enabled = false }