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

vim.api.nvim_exec_autocmds not be called in a lua loop callback #396

Closed
2 tasks done
niuiic opened this issue Nov 28, 2024 · 1 comment
Closed
2 tasks done

vim.api.nvim_exec_autocmds not be called in a lua loop callback #396

niuiic opened this issue Nov 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@niuiic
Copy link
Contributor

niuiic commented Nov 28, 2024

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

image

My solution.

		local event_emitter = require("blink.cmp.lib.event_emitter")
		---@diagnostic disable-next-line: duplicate-set-field
		function event_emitter:emit(data)
			data = data or {}
			data.event = self.event
			for _, callback in ipairs(self.listeners) do
				callback(data)
			end
			if self.autocmd then
				vim.schedule(function()
					vim.api.nvim_exec_autocmds("User", { pattern = self.autocmd, modeline = false, data = data })
				end)
			end
		end

Relevant configuration

No response

neovim version

0.10

blink.cmp version: branch, tag, or commit

main

@niuiic niuiic added the bug Something isn't working label Nov 28, 2024
@soifou
Copy link
Contributor

soifou commented Nov 28, 2024

Same here, my workaround is simply to discard if in fast event:

diff --git a/lua/blink/cmp/lib/event_emitter.lua b/lua/blink/cmp/lib/event_emitter.lua
index 03a60a3..122f9c0 100644
--- a/lua/blink/cmp/lib/event_emitter.lua
+++ b/lua/blink/cmp/lib/event_emitter.lua
@@ -22,6 +22,7 @@ function event_emitter:off(callback)
 end

 function event_emitter:emit(data)
+  if vim.in_fast_event() then return end
   data = data or {}
   data.event = self.event
   for _, callback in ipairs(self.listeners) do

@Saghen Saghen closed this as completed in 9428983 Nov 28, 2024
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

2 participants