@@ -121,8 +121,9 @@ function M.evaluate_choices(meta_props, context, cb)
121121 return cb (sanitized )
122122 elseif type (choices ) == " function" then
123123 local state = {
124- callback_invoked = false ,
124+ callback_invoked = false , -- user's callback was actually called
125125 timer = nil , --- @type uv.uv_timer_t | nil
126+ timed_out = false , -- we gave up waiting, no callback called
126127 bufnr = context .buffer ,
127128 }
128129
@@ -135,6 +136,12 @@ function M.evaluate_choices(meta_props, context, cb)
135136 end
136137
137138 local wrapped_callback = function (items )
139+ if state .timed_out then
140+ -- ignore post-timeout callbacks
141+ return
142+ end
143+
144+ -- did the user invoke the cb more than once? warn
138145 if state .callback_invoked then
139146 vim .notify (
140147 string.format (
@@ -146,12 +153,13 @@ function M.evaluate_choices(meta_props, context, cb)
146153 return
147154 end
148155
156+ state .callback_invoked = true
157+
149158 if not vim .api .nvim_buf_is_valid (state .bufnr ) then
150159 cleanup ()
151160 return
152161 end
153162
154- state .callback_invoked = true
155163 cleanup ()
156164
157165 if type (items ) ~= " table" then
@@ -184,7 +192,7 @@ function M.evaluate_choices(meta_props, context, cb)
184192 0 ,
185193 vim .schedule_wrap (function ()
186194 if not state .callback_invoked then
187- state .callback_invoked = true
195+ state .timed_out = true
188196 cleanup ()
189197 vim .notify (
190198 string.format (" Checkmate: 'choices' function timed out for @%s" , context .name ),
0 commit comments