feat(:restart): v:startreason #40186

Problem:
It's clumsy for scripts to handle a "restart", without custom mappings or
global vars.

Solution:
Introduce `v:startreason`

(cherry picked from commit ae426ee465)
This commit is contained in:
Nathan Zeng
2026-06-18 12:49:12 -07:00
committed by Olivia Kinnear
parent a4985ac902
commit 611b4f8237
12 changed files with 69 additions and 3 deletions

View File

@@ -364,7 +364,15 @@ it(':restart works in headless server (no UI)', function()
n.set_session(nil)
end)
fn.jobstart({ n.nvim_prog, '--clean', '--headless', '--listen', server_pipe })
fn.jobstart({
n.nvim_prog,
'--clean',
'--headless',
'--listen',
server_pipe,
'--cmd',
'let g:early_startreason = v:startreason',
})
t.retry(nil, nil, function()
neq(nil, vim.uv.fs_stat(server_pipe))
end)
@@ -373,6 +381,8 @@ it(':restart works in headless server (no UI)', function()
n.expect_exit(n.command, 'restart')
n.set_session(n.connect(server_pipe))
eq(1, api.nvim_get_vvar('vim_did_enter'))
eq('restart', api.nvim_get_vvar('startreason'))
eq('restart', n.eval('g:early_startreason'))
-- TODO: [command] is currently not executed without UI
-- n.expect_exit(n.command, 'restart lua _G.new_server = 1')