Giter Site home page Giter Site logo

Comments (20)

hrsh7th avatar hrsh7th commented on September 26, 2024 1

You can control the behaviour via

cmp.mapping.confirm({
  behavior = cmp.ConfirmBehavior.Replace,
  select = true,
})

select option value.

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024 1

thank you very much! working now

from nvim-cmp.

megalithic avatar megalithic commented on September 26, 2024 1

Thanks @hrsh7th and @carlitux .. in addition (in the event someone might want this as part of their autopairs setup), i've submitted a PR to nvim-autopairs to address the select=false scenario that @hrsh7th mentioned earlier in this issue thread: windwp/nvim-autopairs#106

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

I wamt to your serup function.

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024
require("cmp_nvim_lsp").setup({})
local lspkind = require("lspkind")

cmp.register_source("look", require("cmp_look").new())

cmp.setup({
	snippet = {
		expand = function(args)
			require("luasnip").lsp_expand(args.body)
		end,
	},
	formatting = {
		format = function(entry, vim_item)
			vim_item.kind = lspkind.presets.default[vim_item.kind]
			return vim_item
		end,
	},
	mapping = {
		['<C-p>'] = cmp.mapping.prev_item(),
		['<C-n>'] = cmp.mapping.next_item(),
		['<C-d>'] = cmp.mapping.scroll(-4),
		['<C-f>'] = cmp.mapping.scroll(4),
		['<C-Space>'] = cmp.mapping.complete(),
		['<C-e>'] = cmp.mapping.close(),
		['<CR>'] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = true,
		})
	},
	sources = {
		{ name = "calc" },
		{ name = "buffer" },
		{ name = "path" },
		-- { name = "look" },
		{ name = "luasnip" },
		{ name = "nvim_lsp" },
	},
})

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

I tried and getting this:

Screencast from 16-08-21 22 36 19

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

Hm... If you use packer.nvim, Please do the PackerUpdate and PackerCompile.

It can't reproduce. Sorry.

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

@hrsh7th I will try to debug, I already executed the packer commands

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

I can't reproduce it with the following minimal 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 !isdirectory(s:plug_dir)
  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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
call plug#end()
PlugInstall | quit

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

local cmp = require'cmp'
cmp.setup({
	snippet = {
		expand = function(args)
			require("luasnip").lsp_expand(args.body)
		end,
	},
	formatting = {
		format = function(entry, vim_item)
			vim_item.kind = lspkind.presets.default[vim_item.kind]
			return vim_item
		end,
	},
	mapping = {
		['<C-p>'] = cmp.mapping.prev_item(),
		['<C-n>'] = cmp.mapping.next_item(),
		['<C-d>'] = cmp.mapping.scroll(-4),
		['<C-f>'] = cmp.mapping.scroll(4),
		['<C-Space>'] = cmp.mapping.complete(),
		['<C-e>'] = cmp.mapping.close(),
		['<CR>'] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = true,
		})
	},
	sources = {
		{ name = "buffer" },
	},
})
EOF

Could you please your full config?

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

Doing simple debug I found this:

{
  ["<C-Space>"] = {
    action = <function 1>,
    modes = { "i" },
    <metatable> = {
      __call = <function 2>
    }
  },
  ["<C-d>"] = {
    action = <function 3>,
    modes = { "i" },
    <metatable> = {
      __call = <function 4>
    }
  },
  ["<C-e>"] = {
    action = <function 5>,
    modes = { "i" },
    <metatable> = {
      __call = <function 6>
    }
  },
  ["<C-f>"] = {
    action = <function 7>,
    modes = { "i" },
    <metatable> = {
      __call = <function 8>
    }
  },
  ["<C-n>"] = {
    action = <function 9>,
    modes = { "i" },
    <metatable> = {
      __call = <function 10>
    }
  },
  ["<C-p>"] = {
    action = <function 11>,
    modes = { "i" },
    <metatable> = {
      __call = <function 12>
    }
  },
  ["<CR>"] = {
    action = <function 13>,
    modes = { "i" }
  }
}

where https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/core.lua#L77 needs the value to be a function but it is a table with keys: action and modes

Edit. as the error is packer/start/nvim-cmp/lua/cmp/core.lua:77: attempt to call a table value

Could you please your full config?

it is big, https://gitlab.com/linkux-it/galaxy

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

looks like it is not calling __call maybe lua version?

NVIM v0.6.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -ffile-prefix-map=/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/config -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/src -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/.deps/usr/include -I/usr/include -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/src/nvim/auto -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/include
Compiled by buildd@lgw01-amd64-022

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info```

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

I tried to use ipairs https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/core.lua#L75 but freeze neovim sometimes and others do nothing

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

The config.get().mapping is dict (not an array). So it should be applied pairs not ipairs.

Hm... I saw your configuration files but I hadn't found anything.

Sorry for annoying but I please you to debug the below steps.

  1. Create minimal vimrc
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 !isdirectory(s:plug_dir)
  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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
call plug#end()
PlugInstall | quit

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

local cmp = require'cmp'
cmp.setup({
	snippet = {
		expand = function(args)
			require("luasnip").lsp_expand(args.body)
		end,
	},
	formatting = {
		format = function(entry, vim_item)
			vim_item.kind = lspkind.presets.default[vim_item.kind]
			return vim_item
		end,
	},
	mapping = {
		['<C-p>'] = cmp.mapping.prev_item(),
		['<C-n>'] = cmp.mapping.next_item(),
		['<C-d>'] = cmp.mapping.scroll(-4),
		['<C-f>'] = cmp.mapping.scroll(4),
		['<C-Space>'] = cmp.mapping.complete(),
		['<C-e>'] = cmp.mapping.close(),
		['<CR>'] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = false,
		})
	},
	sources = {
		{ name = "buffer" },
	},
})
EOF
  1. Use this vimrc
    nvim -u /path/to/minimal_vimrc

  2. Check the problem.

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

After many tests, I found the issue comes with nvim-autopairs. When cmp.setup is called twice the error appears. https://github.com/windwp/nvim-autopairs/blob/master/lua/nvim-autopairs/completion/cmp.lua

I replicated with calling twice the setup

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 !isdirectory(s:plug_dir)
  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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
Plug 'windwp/nvim-autopairs'
call plug#end()
PlugInstall | quit

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

local cmp = require'cmp'
cmp.setup({
	snippet = {
		expand = function(args)
			require("luasnip").lsp_expand(args.body)
		end,
	},
	formatting = {
		format = function(entry, vim_item)
			vim_item.kind = lspkind.presets.default[vim_item.kind]
			return vim_item
		end,
	},
	mapping = {
		['<C-p>'] = cmp.mapping.prev_item(),
		['<C-n>'] = cmp.mapping.next_item(),
		['<C-d>'] = cmp.mapping.scroll(-4),
		['<C-f>'] = cmp.mapping.scroll(4),
		['<C-Space>'] = cmp.mapping.complete(),
		['<C-e>'] = cmp.mapping.close(),
		['<CR>'] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = false,
		})
	},
	sources = {
		{ name = "buffer" },
	},
})
cmp.setup({
	mapping = {
		['<CR>'] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = false,
		})
	},
})
EOF

from nvim-cmp.

megalithic avatar megalithic commented on September 26, 2024

@carlitux good day Luis! I'm hoping I haven't missed a detail here, I'm trying to understand why/where you were calling require('cmp').setup() twice; in other words, aside from the example above where you found the bug, why were you calling it twice originally? I'm having a semi-similar issue in that i have no pum items selected in cmp, and if i hit enter, it automatically selects the first item.

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

@carlitux Thank you very much for your effort!
I will investigate and fix.

@megalithic You can specify select = false to your confirm mapping option.

from nvim-cmp.

carlitux avatar carlitux commented on September 26, 2024

@megalithic already I don't directly. I use https://github.com/windwp/nvim-autopairs and the plugin does with the config for auto-pairs says:

-- you need setup cmp first put this after cmp.setup()
require("nvim-autopairs.completion.cmp").setup({
  map_cr = true, --  map <CR> on insert mode
  map_complete = true, -- it will auto insert `(` after select function or method item
})

from nvim-cmp.

megalithic avatar megalithic commented on September 26, 2024

@carlitux same here, i tried @hrsh7th's suggestion and that sort of worked, but i wonder if it messes with the autopairs plugin mapping that you defined above.

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

@carlitux @megalithic I've fixed the duplicate setup calls.
Could you try with latest nvim-cmp?

from nvim-cmp.

hrsh7th avatar hrsh7th commented on September 26, 2024

If this issue has fixed. feel free to close it.

from nvim-cmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.