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

Execute command after cmp.show #806

Closed
aidancz opened this issue Dec 28, 2024 · 3 comments
Closed

Execute command after cmp.show #806

aidancz opened this issue Dec 28, 2024 · 3 comments
Labels
feature New feature or request keymap

Comments

@aidancz
Copy link

aidancz commented Dec 28, 2024

namely, this setup does not work:

require("blink.cmp").setup({
	completion = {
		menu = {
			auto_show = false,
		},
		list = {
			selection = "auto_insert",
		},
	},
	keymap = {
		preset = "none",
		["<down>"] = {
			function(cmp)
				cmp.show()
				cmp.select_next()
			end,
		},
	},
})

I have this ugly hack as a workaround..

		["<down>"] = {
			function(cmp)
				cmp.show()
				vim.defer_fn(function()
					cmp.select_next()
				end, 1)
			end,
		},
@Saghen Saghen closed this as completed in 33b82e5 Dec 29, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 29, 2024

On main, you can now do cmp.show({ callback = function() cmp.select_next() end })

@Saghen Saghen changed the title how can I execute two commands in parallel? Execute command after cmp.show Dec 29, 2024
@Saghen Saghen added the feature New feature or request label Dec 29, 2024
@aidancz
Copy link
Author

aidancz commented Dec 29, 2024

Thank you for the prompt fix! However, this doesn't seem to work.

with this setup:

require("blink.cmp").setup({
	completion = {
		menu = {
			auto_show = false,
		},
		list = {
			selection = "auto_insert",
		},
	},
	keymap = {
		preset = "none",
		["<down>"] = {
			function(cmp)
				cmp.show({
					callback = function()
						vim.print(cmp.is_visible())
						cmp.select_next()
					end,
				})
			end,
		},
	},
})

I still can't show the menu and immediately select the first candidate when I press the <down> key for the first time.

since when the callback function is invoked, cmp.is_visible() will return false


Is there a more general way to connect two commands?

I want to chain cancel and show too

should I use require('blink.cmp.completion.list').undo_preview() in my config?

@Saghen Saghen reopened this Dec 29, 2024
@Saghen Saghen added the keymap label Dec 29, 2024
@Saghen Saghen closed this as completed in 73a5f4e Dec 30, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 30, 2024

This one was a bit tricky because the internals use events for most communication, but I've worked out a semi hacky solution that seems to work well. I've also added callbacks to .cancel and .hide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request keymap
Projects
None yet
Development

No branches or pull requests

2 participants