Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmp and smart-pairs <CR> confict #7

Closed
ignamartinoli opened this issue Aug 28, 2022 · 12 comments
Closed

cmp and smart-pairs <CR> confict #7

ignamartinoli opened this issue Aug 28, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@ignamartinoli
Copy link

Hey, I really like the idea for your plugin, but unfortunately after installing it, it wasn't working.

I use ZhiyuanLck/smart-pairs for pairs and hrsh7th/nvim-cmp for completion, and to make them both work I had to configure like this issue suggests

require 'cmp'.setup {
	mapping = cmp.mapping.preset.insert {
		['<CR>'] = cmp.mapping(function ()
			if not cmp.confirm { select = false } then
				require 'pairs.enter'.type()
			end
		end)
	}
}

Do you have any suggestion on how to make your plugin work with this workaround?

@gaoDean
Copy link
Owner

gaoDean commented Aug 28, 2022

yeah, I'll have to look into that, let me get back to you

@ignamartinoli
Copy link
Author

ignamartinoli commented Aug 28, 2022

Thanks! I really look forward trying it out :D
For now, using o to go to a newline works perfectly even with checkboxes

@gaoDean
Copy link
Owner

gaoDean commented Aug 28, 2022

Huh, it seems that the order you load the plugins matter, from someone on reddit. Play around with it, and see what happens.

@gaoDean gaoDean added the bug Something isn't working label Aug 28, 2022
@ignamartinoli
Copy link
Author

Could you please point me to that Reddit post? I tried moving around the use declaration but it didn't worked

@gaoDean
Copy link
Owner

gaoDean commented Aug 29, 2022

You could also play around with moving the require setup

@ignamartinoli
Copy link
Author

I have LSP configured as

use {
	'neovim/nvim-lspconfig',
	config = function () require 'lsp' end,
	requires = {
		'antoinemadec/FixCursorHold.nvim',
		'hrsh7th/cmp-nvim-lsp',
		'L3MON4D3/LuaSnip',
		'hrsh7th/cmp-path',
		'hrsh7th/cmp-nvim-lsp',
		'hrsh7th/nvim-cmp',
		'onsails/lspkind-nvim',
		'saadparwaiz1/cmp_luasnip',
		{
			'kosayoda/nvim-lightbulb',
			config = function () require 'nvim-lightbulb'.setup {
				autocmd = { enabled = true }
			} end
		},
		'nvim-telescope/telescope.nvim',
		{
			'ray-x/lsp_signature.nvim',
			config = function () require 'lsp_signature'.setup {
				hint_prefix = ''
			} end
		},
		{
			'williamboman/mason.nvim',
			config = function () require 'mason'.setup() end
		},
		{
			'williamboman/mason-lspconfig.nvim',
			config = function () require 'mason-lspconfig'.setup() end
		}
	}
}

Nothing happens if I do

use {
	'gaoDean/autolist.nvim',
	after = 'nvim-cmp',
	config = function () require 'autolist'.setup() end
}

If I do this

use {
	'gaoDean/autolist.nvim',
	after = 'hrsh7th/nvim-cmp',
	config = function () require 'autolist'.setup() end
}

I get the following error

Dependency hrsh7th/nvim-cmp for { "autolist.nvim" } not found

@gaoDean
Copy link
Owner

gaoDean commented Aug 29, 2022

I am unfamiliar with lsps and packer, but could the error be because nvim-cmp isn't in the root of the packer, instead in "neovim/nvim-lspconfig", so the after can't access it? Also, is autolist's use before lspconfig's use?

@axieax
Copy link

axieax commented Aug 29, 2022

Not sure where you define your setup for nvim-cmp, but you want to call require("autolist").setup() after defining the cmp.mappings when you setup nvim-cmp.

Nothing happens if I do

use {
'gaoDean/autolist.nvim',
after = 'nvim-cmp',
config = function () require 'autolist'.setup() end
}

This won't work because autolist's setup is called after nvim-cmp is loaded, but not after nvim-cmp's setup is loaded (since you don't define it as such).

Check out my config - I managed to get it working with nvim-cmp: https://github.com/axieax/dotconfig/blob/4d193fdb081328c98e3b704639c92eeb0decc2eb/nvim/lua/axie/plugins/init.lua#L825-L834

@ignamartinoli
Copy link
Author

I did some tests, and the issue is on the cmp-nvim mapping.

I have this mapping set to make both cmp-nvim and smart-pairs work together

cmp.setup {
		['<CR>'] = cmp.mapping(function ()
			if not cmp.confirm { select = false } then
				require 'pairs.enter'.type()
			end
		end)
}

If I have the mapping set like this now autolist.nvim works but smart-pairs don't

cmp.setup {
	mapping = cmp.mapping.preset.insert {
		['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true }
	}
}

@ignamartinoli
Copy link
Author

ignamartinoli commented Sep 9, 2022

I found this link: https://github.com/windwp/nvim-autopairs#mapping-cr

It's from another popular auto-pairing plugin, on how to make it work with cmp, it may be useful. I switched to nvim-autopairs and now it your plugin works perfectly, really love it

@gaoDean
Copy link
Owner

gaoDean commented Sep 12, 2022

Oh cool, thanks. Imma close this now, but this this thread is probably gonna be referenced by more people having the same problem.

@gaoDean gaoDean closed this as completed Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants