feat(editor): ":restart" command #33953

Problem:
Developing/troubleshooting plugins has friction because "restarting"
Nvim requires quitting and manually starting again. #32484

Solution:
- Implement a `:restart` command which emits `restart` UI event.
- Handle the `restart` UI event in the builtin TUI client: stop the
  `nvim --embed` server, start a new one, and attach to it.
This commit is contained in:
Sathya Pramodh
2025-06-02 18:24:17 +05:30
committed by GitHub
parent 236243029d
commit 86835b3db3
7 changed files with 206 additions and 6 deletions

View File

@@ -69,6 +69,7 @@
#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/normal.h"
#include "nvim/normal_defs.h"
@@ -101,6 +102,7 @@
#include "nvim/tag.h"
#include "nvim/types_defs.h"
#include "nvim/ui.h"
#include "nvim/ui_client.h"
#include "nvim/undo.h"
#include "nvim/undo_defs.h"
#include "nvim/usercmd.h"
@@ -5592,6 +5594,42 @@ static void ex_detach(exarg_T *eap)
}
}
/// ":restart" command
/// Restarts the server by delegating the work to the UI.
static void ex_restart(exarg_T *eap)
{
bool forceit = eap && eap->forceit;
// Refuse to restart if text is locked (i.e in command line etc.)
if (text_locked()) {
text_locked_msg();
return;
}
// Refuse to restart if buffer is locked.
if (curbuf_locked()) {
return;
}
win_T *wp = curwin;
// If any buffer is changed and not saved, we cannot restart.
// But if called using bang (!), we will force restart.
if ((!buf_hide(wp->w_buffer)
&& check_changed(wp->w_buffer, (p_awa ? CCGD_AW : 0)
| (forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD))
|| check_more(true, forceit) == FAIL
|| check_changed_any(forceit, true)) {
if (!forceit) {
return;
}
}
// Send an ui restart event.
ui_call_restart();
}
/// ":mode":
/// If no argument given, get the screen size and redraw.
static void ex_mode(exarg_T *eap)