fix(startup): make recovery mode work without --headless (#24477)

This commit is contained in:
zeertzjq 2023-07-25 19:02:39 +08:00 committed by GitHub
parent 7668f89d5b
commit c0fa721ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

View File

@ -305,6 +305,16 @@ int main(int argc, char **argv)
} }
} }
if (GARGCOUNT > 0) {
fname = get_fname(&params, cwd);
}
// Recovery mode without a file name: List swap files.
// In this case, no UI is needed.
if (recoverymode && fname == NULL) {
headless_mode = true;
}
#ifdef MSWIN #ifdef MSWIN
// on windows we use CONIN special file, thus we don't know this yet. // on windows we use CONIN special file, thus we don't know this yet.
bool has_term = true; bool has_term = true;
@ -336,16 +346,6 @@ int main(int argc, char **argv)
ui_client_channel_id = rv; ui_client_channel_id = rv;
} }
if (GARGCOUNT > 0) {
fname = get_fname(&params, cwd);
}
// Recovery mode without a file name: List swap files.
// In this case, no UI is needed.
if (recoverymode && fname == NULL) {
headless_mode = true;
}
TIME_MSG("expanding arguments"); TIME_MSG("expanding arguments");
if (params.diff_mode && params.window_count == -1) { if (params.diff_mode && params.window_count == -1) {

View File

@ -43,7 +43,6 @@ describe('Remote', function()
local function run_remote(...) local function run_remote(...)
set_session(server) set_session(server)
local addr = funcs.serverlist()[1] local addr = funcs.serverlist()[1]
local client_argv = { nvim_prog, '--clean', '--headless', '--server', addr, ... }
-- Create an nvim instance just to run the remote-invoking nvim. We want -- Create an nvim instance just to run the remote-invoking nvim. We want
-- to wait for the remote instance to exit and calling jobwait blocks -- to wait for the remote instance to exit and calling jobwait blocks
@ -52,7 +51,7 @@ describe('Remote', function()
local client_starter = spawn(new_argv(), false, nil, true) local client_starter = spawn(new_argv(), false, nil, true)
set_session(client_starter) set_session(client_starter)
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(..., { eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, {
stdout_buffered = true, stdout_buffered = true,
stderr_buffered = true, stderr_buffered = true,
on_stdout = function(_, data, _) on_stdout = function(_, data, _)
@ -61,7 +60,7 @@ describe('Remote', function()
on_stderr = function(_, data, _) on_stderr = function(_, data, _)
_G.Remote_stderr = table.concat(data, '\n') _G.Remote_stderr = table.concat(data, '\n')
end, end,
}) })]], client_argv)) }) })]], nvim_prog, '--clean', '--headless', '--server', addr, ...))
local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]]) local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]])
client_starter:close() client_starter:close()
set_session(server) set_session(server)

View File

@ -21,6 +21,7 @@ local nvim_set = helpers.nvim_set
local read_file = helpers.read_file local read_file = helpers.read_file
local retry = helpers.retry local retry = helpers.retry
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local skip = helpers.skip
local sleep = helpers.sleep local sleep = helpers.sleep
local startswith = helpers.startswith local startswith = helpers.startswith
local write_file = helpers.write_file local write_file = helpers.write_file
@ -460,6 +461,18 @@ describe('startup', function()
]]) ]])
end) end)
it('-r works without --headless in PTY #23294', function()
skip(is_os('win'))
eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart({...}, {
pty = true,
stdout_buffered = true,
on_stdout = function(_, data, _)
_G.Recovery_stdout = data
end,
}) })]], nvim_prog, '-u', 'NONE', '-i', 'NONE', '-r'))
matches('Swap files found:\r*', exec_lua('return _G.Recovery_stdout[1]'))
end)
it('fixed hang issue with --headless (#11386)', function() it('fixed hang issue with --headless (#11386)', function()
local expected = '' local expected = ''
local period = 100 local period = 100