commit e4d3812c8bd81e7aa72ebf6e1675a67d084a0da6
parent 2211953266f7d01462e38b7f885bdc6a0afb62a0
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon, 18 Aug 2025 09:43:34 +0800
Merge pull request #35370 from zeertzjq/excmd
:connect fixes
Diffstat:
4 files changed, 65 insertions(+), 62 deletions(-)
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
@@ -583,12 +583,6 @@ M.cmds = {
func = 'ex_menu',
},
{
- command = 'connect',
- flags = bit.bor(BANG, WORD1, NOTRLCOM, NEEDARG),
- addr_type = 'ADDR_NONE',
- func = 'ex_connect',
- },
- {
command = 'copy',
flags = bit.bor(RANGE, WHOLEFOLD, EXTRA, TRLBAR, CMDWIN, LOCK_OK, MODIFY),
addr_type = 'ADDR_LINES',
@@ -637,6 +631,12 @@ M.cmds = {
func = 'ex_wrongmodifier',
},
{
+ command = 'connect',
+ flags = bit.bor(BANG, WORD1, NOTRLCOM, NEEDARG),
+ addr_type = 'ADDR_NONE',
+ func = 'ex_connect',
+ },
+ {
command = 'const',
flags = bit.bor(EXTRA, NOTRLCOM, SBOXOK, CMDWIN, LOCK_OK),
addr_type = 'ADDR_NONE',
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c
@@ -290,6 +290,8 @@ void ui_client_event_connect(Array args)
char *server_addr = args.items[0].data.string.data;
multiqueue_put(main_loop.fast_events, channel_connect_event, server_addr);
+ // Set a dummy channel ID to prevent client exit when server detaches.
+ ui_client_channel_id = UINT64_MAX;
}
static void channel_connect_event(void **argv)
@@ -302,15 +304,16 @@ static void channel_connect_event(void **argv)
uint64_t chan = channel_connect(is_tcp, server_addr, true, on_data, 50, &err);
if (!strequal(err, "")) {
- ELOG("Error handling UI event 'connect': %s", err);
- return;
+ ELOG("Cannot connect to server %s: %s", server_addr, err);
+ ui_client_exit_status = 1;
+ os_exit(1);
}
ui_client_channel_id = chan;
ui_client_is_remote = true;
ui_client_attach(tui_width, tui_height, tui_term, tui_rgb);
- ELOG("Connected to channel: %" PRId64, chan);
+ ILOG("Connected to server %s on channel %" PRId64, server_addr, chan);
}
/// When a "restart" UI event is received, its arguments are saved here when
diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua
@@ -62,4 +62,17 @@ describe('Ex cmds', function()
eq(2, fn.exists(':defer'))
eq('defer', fn.fullcommand('defer'))
end)
+
+ it('various command abbreviations', function()
+ -- :connect needs at least :conn
+ eq('change', fn.fullcommand('c'))
+ eq('copy', fn.fullcommand('co'))
+ eq('continue', fn.fullcommand('con'))
+ eq('connect', fn.fullcommand('conn'))
+ -- :restart needs at least :rest
+ eq('read', fn.fullcommand('r'))
+ eq('read', fn.fullcommand('re'))
+ eq('resize', fn.fullcommand('res'))
+ eq('restart', fn.fullcommand('rest'))
+ end)
end)
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
@@ -318,6 +318,7 @@ describe('TUI :restart', function()
-- Cancel the operation (abandons restart).
tt.feed_data('C\013')
+ screen:expect({ any = vim.pesc('[No Name]') })
-- Check ":confirm restart <cmd>" on a modified buffer.
tt.feed_data(':confirm restart echo "Hello"\013')
@@ -370,6 +371,12 @@ describe('TUI :connect', function()
return
end
+ local screen_empty = [[
+ ^ |
+ {100:~ }|*5
+ |
+ ]]
+
it('leaves the current server running', function()
n.clear()
finally(function()
@@ -377,61 +384,45 @@ describe('TUI :connect', function()
end)
local server1 = new_pipename()
- local screen = tt.setup_child_nvim({
- '--listen',
- server1,
- '-u',
- 'NONE',
- })
+ local screen1 = tt.setup_child_nvim({ '--listen', server1, '--clean' })
+ screen1:expect({ any = vim.pesc('[No Name]') })
tt.feed_data(':connect\013')
- screen:expect([[
- ^ |
- ~ |*3
- [No Name] 0,0-1 All|
- E471: Argument required |
- {5:-- TERMINAL --} |
- ]])
+ screen1:expect({ any = 'E471: Argument required' })
- screen:detach()
+ tt.feed_data('iThis is server 1.\027')
+ screen1:expect({ any = vim.pesc('This is server 1^.') })
+
+ -- Prevent screen2 from receiving the old terminal state.
+ command('enew')
+ screen1:expect(screen_empty)
+ screen1:detach()
local server2 = new_pipename()
- local screen2 = tt.setup_child_nvim({
- '--listen',
- server2,
- '-u',
- 'NONE',
- })
+ local screen2 = tt.setup_child_nvim({ '--listen', server2, '--clean' })
+ screen2:expect({ any = vim.pesc('[No Name]') })
+
tt.feed_data('iThis is server 2.\027')
- tt.feed_data(':connect ' .. server1 .. '\013')
+ screen2:expect({ any = vim.pesc('This is server 2^.') })
- screen2:expect({
- any = [[Process exited]],
- })
+ tt.feed_data(':connect ' .. server1 .. '\013')
+ screen2:expect({ any = vim.pesc('This is server 1^.') })
local server1_session = n.connect(server1)
server1_session:request('nvim_command', 'qall!')
+ screen2:expect({ any = [[Process exited]] })
screen2:detach()
local server2_session = n.connect(server2)
- local screen3 = tt.setup_child_nvim({
- '--remote-ui',
- '--server',
- server2,
- })
- screen3:expect([[
- This is server 2^. |
- ~ |*3
- {2:[No Name] [+] 1,17 All}|
- |
- {5:-- TERMINAL --} |
- ]])
+ local screen3 = tt.setup_child_nvim({ '--remote-ui', '--server', server2 })
+ screen3:expect({ any = vim.pesc('This is server 2^.') })
screen3:detach()
server2_session:request('nvim_command', 'qall!')
end)
+
it('! stops the current server', function()
n.clear()
finally(function()
@@ -439,27 +430,23 @@ describe('TUI :connect', function()
end)
local server1 = new_pipename()
- local screen1 = tt.setup_child_nvim({
- '--listen',
- server1,
- })
- tt.feed_data('iThis is server 1')
+ local screen1 = tt.setup_child_nvim({ '--listen', server1, '--clean' })
+ screen1:expect({ any = vim.pesc('[No Name]') })
+ tt.feed_data('iThis is server 1.\027')
+ screen1:expect({ any = vim.pesc('This is server 1^.') })
+
+ -- Prevent screen2 from receiving the old terminal state.
+ command('enew')
+ screen1:expect(screen_empty)
screen1:detach()
local server2 = new_pipename()
- local screen2 = tt.setup_child_nvim({
- '--listen',
- server2,
- })
- tt.feed_data('\027:connect! ' .. server1 .. '\013')
- screen2:expect([[
- This is server 1^ |
- ~ |*3
- [No Name] [+] 1,17 All|
- -- INSERT -- |
- {5:-- TERMINAL --} |
- ]])
+ local screen2 = tt.setup_child_nvim({ '--listen', server2, '--clean' })
+ screen2:expect({ any = vim.pesc('[No Name]') })
+
+ tt.feed_data(':connect! ' .. server1 .. '\013')
+ screen2:expect({ any = vim.pesc('This is server 1^.') })
local server1_session = n.connect(server1)
server1_session:request('nvim_command', 'qall!')