mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(api): fix not capturing output in cmdline mode (#35322)
This commit is contained in:
@@ -726,6 +726,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Arena
|
||||
|
||||
garray_T capture_local;
|
||||
const int save_msg_silent = msg_silent;
|
||||
const bool save_redir_off = redir_off;
|
||||
garray_T * const save_capture_ga = capture_ga;
|
||||
const int save_msg_col = msg_col;
|
||||
|
||||
@@ -737,6 +738,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Arena
|
||||
TRY_WRAP(err, {
|
||||
if (opts->output) {
|
||||
msg_silent++;
|
||||
redir_off = false;
|
||||
msg_col = 0; // prevent leading spaces
|
||||
}
|
||||
|
||||
@@ -747,6 +749,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Arena
|
||||
if (opts->output) {
|
||||
capture_ga = save_capture_ga;
|
||||
msg_silent = save_msg_silent;
|
||||
redir_off = save_redir_off;
|
||||
// Put msg_col back where it was, since nothing should have been written.
|
||||
msg_col = save_msg_col;
|
||||
}
|
||||
|
@@ -72,6 +72,7 @@ Dict nvim_exec2(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *e
|
||||
String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *err)
|
||||
{
|
||||
const int save_msg_silent = msg_silent;
|
||||
const bool save_redir_off = redir_off;
|
||||
garray_T *const save_capture_ga = capture_ga;
|
||||
const int save_msg_col = msg_col;
|
||||
garray_T capture_local;
|
||||
@@ -83,6 +84,7 @@ String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *
|
||||
TRY_WRAP(err, {
|
||||
if (opts->output) {
|
||||
msg_silent++;
|
||||
redir_off = false;
|
||||
msg_col = 0; // prevent leading spaces
|
||||
}
|
||||
|
||||
@@ -92,6 +94,7 @@ String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *
|
||||
if (opts->output) {
|
||||
capture_ga = save_capture_ga;
|
||||
msg_silent = save_msg_silent;
|
||||
redir_off = save_redir_off;
|
||||
// Put msg_col back where it was, since nothing should have been written.
|
||||
msg_col = save_msg_col;
|
||||
}
|
||||
|
@@ -385,6 +385,9 @@ describe('API', function()
|
||||
)
|
||||
eq({ output = '' }, api.nvim_exec2('echo', { output = true }))
|
||||
eq({ output = 'foo 42' }, api.nvim_exec2('echo "foo" 42', { output = true }))
|
||||
-- Returns output in cmdline mode #35321
|
||||
feed(':')
|
||||
eq({ output = 'foo 42' }, api.nvim_exec2('echo "foo" 42', { output = true }))
|
||||
end)
|
||||
|
||||
it('displays messages when opts.output=false', function()
|
||||
@@ -4945,6 +4948,9 @@ describe('API', function()
|
||||
|
||||
it('captures output', function()
|
||||
eq('foo', api.nvim_cmd({ cmd = 'echo', args = { '"foo"' } }, { output = true }))
|
||||
-- Returns output in cmdline mode #35321
|
||||
feed(':')
|
||||
eq('foo', api.nvim_cmd({ cmd = 'echo', args = { '"foo"' } }, { output = true }))
|
||||
end)
|
||||
|
||||
it('sets correct script context', function()
|
||||
|
Reference in New Issue
Block a user