hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.47k stars 370 forks source link

Extra TS text appearing when doing cmp.mapping.select_next_item() #1800

Closed anurag3301 closed 5 months ago

anurag3301 commented 5 months ago

FAQ

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }))
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local nvim_lsp = require('lspconfig')
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

nvim_lsp['ccls'].setup {
    on_attach = on_attach,
    capabilities = capabilities,
    flags = {
        debounce_text_changes = 150,
    },
    init_options = {
        cache = {
            directory = "/tmp/ccls-cache"
        }
    },
    root_dir = function() return vim.loop.cwd() end
}
EOF

Description

I have mapped <Tab> for select_next_item as shown below

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }))
  },

I am getting this syntactic text which seems like to be some TreeSitter text when I press tab image They do get disappear when I press Enter which calls cmp.mapping.confirm({ select = true }) but most of time I just press tab and continue programming instead of pressing Enter. This doesnt seem like expected behavior.

Steps to reproduce

Just try the above given minimal config, I have changed only two section

Mapping

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
+   ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }))
  },

Lsp Config for CCSL

lua << EOF

local nvim_lsp = require('lspconfig')

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

nvim_lsp['ccls'].setup {
    on_attach = on_attach,
    capabilities = capabilities,
    flags = {
        debounce_text_changes = 150,
    },
    init_options = {
        cache = {
            directory = "/tmp/ccls-cache"
        }
    },
    root_dir = function() return vim.loop.cwd() end
}
EOF

Expected behavior

Maybe not showing those extra text.

Actual behavior

image image

Additional context

But this problem is not consistent, it appears for some functions, not for others this one image

Not sure whose problem is it, is the nvim's lsp client, ccls or cmp.

Thank you for your contribution. :)

Shougo commented 5 months ago

Please see this.

https://github.com/hrsh7th/nvim-cmp/issues/645

anurag3301 commented 5 months ago

@Shougo thanks for the tip. It sure helps with it :)

I'll close the issue as it's a duplicate.

anurag3301 commented 5 months ago

Wait, should I keep it open?

Shougo commented 5 months ago

I think it should be closed. Because it is not nvim-cmp issue.