mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	fix(lua): make it possible to cancel vim.wait() with Ctrl-C (#19217)
This commit is contained in:
		@@ -416,9 +416,9 @@ static int nlua_wait(lua_State *lstate)
 | 
			
		||||
  LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
 | 
			
		||||
                            loop_events,
 | 
			
		||||
                            (int)timeout,
 | 
			
		||||
                            is_function ? nlua_wait_condition(lstate,
 | 
			
		||||
                                                              &pcall_status,
 | 
			
		||||
                                                              &callback_result) : false || got_int);
 | 
			
		||||
                            got_int || (is_function ? nlua_wait_condition(lstate,
 | 
			
		||||
                                                                          &pcall_status,
 | 
			
		||||
                                                                          &callback_result) : false));
 | 
			
		||||
 | 
			
		||||
  // Stop dummy timer
 | 
			
		||||
  time_watcher_stop(tw);
 | 
			
		||||
 
 | 
			
		||||
@@ -2493,6 +2493,41 @@ describe('lua stdlib', function()
 | 
			
		||||
 | 
			
		||||
      eq(false, pcall_result)
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    describe('returns -2 when interrupted', function()
 | 
			
		||||
      before_each(function()
 | 
			
		||||
        local channel = meths.get_api_info()[1]
 | 
			
		||||
        meths.set_var('channel', channel)
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('without callback', function()
 | 
			
		||||
        exec_lua([[
 | 
			
		||||
          function _G.Wait()
 | 
			
		||||
            vim.rpcnotify(vim.g.channel, 'ready')
 | 
			
		||||
            local _, interrupted = vim.wait(4000)
 | 
			
		||||
            vim.rpcnotify(vim.g.channel, 'wait', interrupted)
 | 
			
		||||
          end
 | 
			
		||||
        ]])
 | 
			
		||||
        feed(':lua _G.Wait()<CR>')
 | 
			
		||||
        eq({'notification', 'ready', {}}, next_msg(500))
 | 
			
		||||
        feed('<C-C>')
 | 
			
		||||
        eq({'notification', 'wait', {-2}}, next_msg(500))
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('with callback', function()
 | 
			
		||||
        exec_lua([[
 | 
			
		||||
          function _G.Wait()
 | 
			
		||||
            vim.rpcnotify(vim.g.channel, 'ready')
 | 
			
		||||
            local _, interrupted = vim.wait(4000, function() end)
 | 
			
		||||
            vim.rpcnotify(vim.g.channel, 'wait', interrupted)
 | 
			
		||||
          end
 | 
			
		||||
        ]])
 | 
			
		||||
        feed(':lua _G.Wait()<CR>')
 | 
			
		||||
        eq({'notification', 'ready', {}}, next_msg(500))
 | 
			
		||||
        feed('<C-C>')
 | 
			
		||||
        eq({'notification', 'wait', {-2}}, next_msg(500))
 | 
			
		||||
      end)
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  it('vim.notify_once', function()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user