From b162adbb7ca4f980e938a4a06a49218a9ed496cf Mon Sep 17 00:00:00 2001 From: nikolightsaber <103886134+nikolightsaber@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:59:31 +0100 Subject: feat(api): pass 0 to nvim_get_chan_info for current channel (#27321) Getting current channel info was kind of annoying via RPC. Two functions had to be called: 1. `nvim_get_api_info` which returns `[channel_id, meta_data]`. - This results in `channel_id = api.nvim_get_api_info()[0]`. - Here the meta_data is sent but never used. 2. Finally call `nvim_get_chan_info(channel_id)`. This commit reduces the need for `nvim_get_api_info` as passing 0 returns current channel info. --- test/functional/api/vim_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 4cd46f5e91..15b05e4de7 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2449,7 +2449,6 @@ describe('API', function() } it('returns {} for invalid channel', function() - eq({}, api.nvim_get_chan_info(0)) eq({}, api.nvim_get_chan_info(-1)) -- more preallocated numbers might be added, try something high eq({}, api.nvim_get_chan_info(10)) @@ -2457,6 +2456,8 @@ describe('API', function() it('stream=stdio channel', function() eq({ [1] = testinfo, [2] = stderr }, api.nvim_list_chans()) + -- 0 should return current channel + eq(testinfo, api.nvim_get_chan_info(0)) eq(testinfo, api.nvim_get_chan_info(1)) eq(stderr, api.nvim_get_chan_info(2)) @@ -2522,6 +2523,7 @@ describe('API', function() "Vim:Error invoking 'nvim_set_current_buf' on channel 3 (amazing-cat):\nWrong type for argument 1 when calling nvim_set_current_buf, expecting Buffer", pcall_err(eval, 'rpcrequest(3, "nvim_set_current_buf", -1)') ) + eq(info, eval('rpcrequest(3, "nvim_get_chan_info", 0)')) end) it('stream=job :terminal channel', function() -- cgit