feat(ex_cmds): consistent :restart behavior (#36723)

This commit is contained in:
Olivia Kinnear
2025-11-30 05:14:28 -05:00
committed by GitHub
parent c87d92c3b4
commit 12d4c624bb
3 changed files with 26 additions and 22 deletions

View File

@@ -73,25 +73,23 @@ Restart Nvim
:restart [+cmd] [command]
Restarts Nvim.
1. Stops Nvim using `:qall!` (or |+cmd|, if given).
1. Stops Nvim using `:qall` (or |+cmd|, if given).
2. Starts a new Nvim server using the same |v:argv|,
optionally running [command] at startup. |-c|
3. Attaches the current UI to the new Nvim server. Other UIs
(if any) will not reattach on restart (this may change in
the future).
Use with `:confirm` to prompt if changes have been made.
Example: stop with `:qall!`, then restart: >
Example: discard changes and stop with `:qall!`, then restart: >
:restart +qall!
< Example: restart and restore the current session: >
:mksession! Session.vim | restart source Session.vim
< Example: restart and update plugins: >
:restart +qall! lua vim.pack.update()
:restart lua vim.pack.update()
<
Note: Only works if the UI and server are on the same system.
Note: If the UI hasn't implemented the "restart" UI event,
this command is equivalent to `:qall!`.
this command is equivalent to `:qall` (or |+cmd|, if given).
------------------------------------------------------------------------------
Connect UI to a different server

View File

@@ -4906,23 +4906,19 @@ static void ex_restart(exarg_T *eap)
set_vim_var_list(VV_ARGV, argv_cpy);
}
bool confirm = (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM));
if (confirm && check_changed_any(false, false)) {
return;
}
char *quit_cmd = (eap->do_ecmd_cmd) ? eap->do_ecmd_cmd : "qall";
char *quit_cmd_copy = NULL;
char *quit_cmd;
if (eap->do_ecmd_cmd) {
quit_cmd = eap->do_ecmd_cmd;
} else if (confirm) {
quit_cmd = "qall";
} else {
quit_cmd = "qall!";
// Prepend "confirm " to cmd if :confirm is used
if (cmdmod.cmod_flags & CMOD_CONFIRM) {
quit_cmd_copy = concat_str("confirm ", quit_cmd);
quit_cmd = quit_cmd_copy;
}
Error err = ERROR_INIT;
restarting = true;
nvim_command(cstr_as_string(quit_cmd), &err);
xfree(quit_cmd_copy);
if (ERROR_SET(&err)) {
emsg(err.msg); // Could not exit
api_clear_error(&err);

View File

@@ -351,8 +351,8 @@ describe('TUI :restart', function()
restart_pid_check()
gui_running_check()
-- Check ":restart +qall" on an unmodified buffer.
tt.feed_data(':restart +qall\013')
-- Check ":restart +qall!" on an unmodified buffer.
tt.feed_data(':restart +qall!\013')
screen_expect(s0)
restart_pid_check()
gui_running_check()
@@ -397,8 +397,18 @@ describe('TUI :restart', function()
restart_pid_check()
gui_running_check()
-- Check ":restart" on the modified buffer.
-- Check ":confirm restart +echo" correctly ignores ":confirm"
tt.feed_data(':confirm restart +echo\013')
screen:expect({ any = vim.pesc('+cmd did not quit the server') })
-- Check ":restart" on a modified buffer.
tt.feed_data('ithis will be removed\027')
tt.feed_data(':restart\013')
screen:expect({ any = vim.pesc('Vim(qall):E37: No write since last change') })
-- Check ":restart +qall!" on a modified buffer.
tt.feed_data('ithis will be removed\027')
tt.feed_data(':restart +qall!\013')
screen_expect(s0)
restart_pid_check()
gui_running_check()
@@ -3979,7 +3989,7 @@ describe('TUI client', function()
-- Run :restart on the remote client.
-- The remote client should start a new server while the original one should exit.
feed_data(':restart\n')
feed_data(':restart +qall!\n')
screen_client:expect([[
^ |
{100:~ }|*3
@@ -4081,7 +4091,7 @@ describe('TUI client', function()
-- Run :restart on the client.
-- The client should start a new server while the original server should exit.
feed_data(':restart\n')
feed_data(':restart +qall!\n')
screen_client:expect([[
^ |
{100:~ }|*4