mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +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;
|
garray_T capture_local;
|
||||||
const int save_msg_silent = msg_silent;
|
const int save_msg_silent = msg_silent;
|
||||||
|
const bool save_redir_off = redir_off;
|
||||||
garray_T * const save_capture_ga = capture_ga;
|
garray_T * const save_capture_ga = capture_ga;
|
||||||
const int save_msg_col = msg_col;
|
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, {
|
TRY_WRAP(err, {
|
||||||
if (opts->output) {
|
if (opts->output) {
|
||||||
msg_silent++;
|
msg_silent++;
|
||||||
|
redir_off = false;
|
||||||
msg_col = 0; // prevent leading spaces
|
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) {
|
if (opts->output) {
|
||||||
capture_ga = save_capture_ga;
|
capture_ga = save_capture_ga;
|
||||||
msg_silent = save_msg_silent;
|
msg_silent = save_msg_silent;
|
||||||
|
redir_off = save_redir_off;
|
||||||
// Put msg_col back where it was, since nothing should have been written.
|
// Put msg_col back where it was, since nothing should have been written.
|
||||||
msg_col = save_msg_col;
|
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)
|
String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *err)
|
||||||
{
|
{
|
||||||
const int save_msg_silent = msg_silent;
|
const int save_msg_silent = msg_silent;
|
||||||
|
const bool save_redir_off = redir_off;
|
||||||
garray_T *const save_capture_ga = capture_ga;
|
garray_T *const save_capture_ga = capture_ga;
|
||||||
const int save_msg_col = msg_col;
|
const int save_msg_col = msg_col;
|
||||||
garray_T capture_local;
|
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, {
|
TRY_WRAP(err, {
|
||||||
if (opts->output) {
|
if (opts->output) {
|
||||||
msg_silent++;
|
msg_silent++;
|
||||||
|
redir_off = false;
|
||||||
msg_col = 0; // prevent leading spaces
|
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) {
|
if (opts->output) {
|
||||||
capture_ga = save_capture_ga;
|
capture_ga = save_capture_ga;
|
||||||
msg_silent = save_msg_silent;
|
msg_silent = save_msg_silent;
|
||||||
|
redir_off = save_redir_off;
|
||||||
// Put msg_col back where it was, since nothing should have been written.
|
// Put msg_col back where it was, since nothing should have been written.
|
||||||
msg_col = save_msg_col;
|
msg_col = save_msg_col;
|
||||||
}
|
}
|
||||||
|
@@ -385,6 +385,9 @@ describe('API', function()
|
|||||||
)
|
)
|
||||||
eq({ output = '' }, api.nvim_exec2('echo', { output = true }))
|
eq({ output = '' }, api.nvim_exec2('echo', { output = true }))
|
||||||
eq({ output = 'foo 42' }, api.nvim_exec2('echo "foo" 42', { 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)
|
end)
|
||||||
|
|
||||||
it('displays messages when opts.output=false', function()
|
it('displays messages when opts.output=false', function()
|
||||||
@@ -4945,6 +4948,9 @@ describe('API', function()
|
|||||||
|
|
||||||
it('captures output', function()
|
it('captures output', function()
|
||||||
eq('foo', api.nvim_cmd({ cmd = 'echo', args = { '"foo"' } }, { output = true }))
|
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)
|
end)
|
||||||
|
|
||||||
it('sets correct script context', function()
|
it('sets correct script context', function()
|
||||||
|
Reference in New Issue
Block a user