mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
fix(remote): make --remote-expr print to stdout
(cherry picked from commit 54a05558e6
)
This commit is contained in:
parent
adea8885c4
commit
4dafd5341a
@ -839,7 +839,7 @@ function vim._cs_remote(rcid, server_addr, connect_error, args)
|
||||
or subcmd == 'tab-wait'
|
||||
or subcmd == 'tab-wait-silent'
|
||||
then
|
||||
return { errmsg = 'E5600: Wait commands not yet implemented in nvim' }
|
||||
return { errmsg = 'E5600: Wait commands not yet implemented in Nvim' }
|
||||
elseif subcmd == 'tab-silent' then
|
||||
f_tab = true
|
||||
f_silent = true
|
||||
@ -853,8 +853,9 @@ function vim._cs_remote(rcid, server_addr, connect_error, args)
|
||||
if rcid == 0 then
|
||||
return { errmsg = connection_failure_errmsg('Send expression failed.') }
|
||||
end
|
||||
print(vim.fn.rpcrequest(rcid, 'nvim_eval', args[2]))
|
||||
return { should_exit = true, tabbed = false }
|
||||
local expr = 'string(' .. args[2] .. ')'
|
||||
local res = vim.fn.rpcrequest(rcid, 'nvim_eval', expr)
|
||||
return { result = res, should_exit = true, tabbed = false }
|
||||
elseif subcmd ~= '' then
|
||||
return { errmsg = 'Unknown option argument: ' .. args[1] }
|
||||
end
|
||||
|
@ -950,7 +950,7 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr,
|
||||
TriState tabbed = kNone;
|
||||
|
||||
for (size_t i = 0; i < rvobj.data.dictionary.size; i++) {
|
||||
if (strcmp(rvobj.data.dictionary.items[i].key.data, "errmsg") == 0) {
|
||||
if (strequal(rvobj.data.dictionary.items[i].key.data, "errmsg")) {
|
||||
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) {
|
||||
os_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n");
|
||||
os_exit(2);
|
||||
@ -958,13 +958,20 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr,
|
||||
os_errmsg(rvobj.data.dictionary.items[i].value.data.string.data);
|
||||
os_errmsg("\n");
|
||||
os_exit(2);
|
||||
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) {
|
||||
} else if (strequal(rvobj.data.dictionary.items[i].key.data, "result")) {
|
||||
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) {
|
||||
os_errmsg("vim._cs_remote returned an unexpected type for 'result'\n");
|
||||
os_exit(2);
|
||||
}
|
||||
os_msg(rvobj.data.dictionary.items[i].value.data.string.data);
|
||||
os_msg("\n");
|
||||
} else if (strequal(rvobj.data.dictionary.items[i].key.data, "tabbed")) {
|
||||
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
|
||||
os_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n");
|
||||
os_exit(2);
|
||||
}
|
||||
tabbed = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse;
|
||||
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) {
|
||||
} else if (strequal(rvobj.data.dictionary.items[i].key.data, "should_exit")) {
|
||||
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
|
||||
os_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n");
|
||||
os_exit(2);
|
||||
|
@ -8,6 +8,8 @@ local exec_lua = helpers.exec_lua
|
||||
local expect = helpers.expect
|
||||
local funcs = helpers.funcs
|
||||
local insert = helpers.insert
|
||||
local is_os = helpers.is_os
|
||||
local nvim_prog = helpers.nvim_prog
|
||||
local new_argv = helpers.new_argv
|
||||
local neq = helpers.neq
|
||||
local set_session = helpers.set_session
|
||||
@ -38,10 +40,11 @@ describe('Remote', function()
|
||||
server:close()
|
||||
end)
|
||||
|
||||
-- Run a `nvim --remote*` command and return { stdout, stderr } of the process
|
||||
local function run_remote(...)
|
||||
set_session(server)
|
||||
local addr = funcs.serverlist()[1]
|
||||
local client_argv = new_argv({args={'--server', addr, ...}})
|
||||
local client_argv = { nvim_prog, '--clean', '--headless', '--server', addr, ... }
|
||||
|
||||
-- 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
|
||||
@ -50,32 +53,43 @@ describe('Remote', function()
|
||||
local client_starter = spawn(new_argv(), false, nil, true)
|
||||
set_session(client_starter)
|
||||
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
|
||||
eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], client_argv))
|
||||
eq({ 0 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(..., {
|
||||
stdout_buffered = true,
|
||||
stderr_buffered = true,
|
||||
on_stdout = function(_, data, _)
|
||||
_G.Remote_stdout = table.concat(data, '\n')
|
||||
end,
|
||||
on_stderr = function(_, data, _)
|
||||
_G.Remote_stderr = table.concat(data, '\n')
|
||||
end,
|
||||
}) })]], client_argv))
|
||||
local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]])
|
||||
client_starter:close()
|
||||
set_session(server)
|
||||
return res
|
||||
end
|
||||
|
||||
it('edit a single file', function()
|
||||
run_remote('--remote', fname)
|
||||
eq({ '', '' }, run_remote('--remote', fname))
|
||||
expect(contents)
|
||||
eq(2, #funcs.getbufinfo())
|
||||
end)
|
||||
|
||||
it('tab edit a single file with a non-changed buffer', function()
|
||||
run_remote('--remote-tab', fname)
|
||||
eq({ '', '' }, run_remote('--remote-tab', fname))
|
||||
expect(contents)
|
||||
eq(1, #funcs.gettabinfo())
|
||||
end)
|
||||
|
||||
it('tab edit a single file with a changed buffer', function()
|
||||
insert('hello')
|
||||
run_remote('--remote-tab', fname)
|
||||
eq({ '', '' }, run_remote('--remote-tab', fname))
|
||||
expect(contents)
|
||||
eq(2, #funcs.gettabinfo())
|
||||
end)
|
||||
|
||||
it('edit multiple files', function()
|
||||
run_remote('--remote', fname, other_fname)
|
||||
eq({ '', '' }, run_remote('--remote', fname, other_fname))
|
||||
expect(contents)
|
||||
command('next')
|
||||
expect(other_contents)
|
||||
@ -83,7 +97,7 @@ describe('Remote', function()
|
||||
end)
|
||||
|
||||
it('send keys', function()
|
||||
run_remote('--remote-send', ':edit '..fname..'<CR><C-W>v')
|
||||
eq({ '', '' }, run_remote('--remote-send', ':edit '..fname..'<CR><C-W>v'))
|
||||
expect(contents)
|
||||
eq(2, #funcs.getwininfo())
|
||||
-- Only a single buffer as we're using edit and not drop like --remote does
|
||||
@ -91,7 +105,9 @@ describe('Remote', function()
|
||||
end)
|
||||
|
||||
it('evaluate expressions', function()
|
||||
run_remote('--remote-expr', 'setline(1, "Yo")')
|
||||
local linesep = is_os('win') and '\r\n' or '\n'
|
||||
eq({ "function('get')" .. linesep, '' }, run_remote('--remote-expr', 'function("get")'))
|
||||
eq({ '0' .. linesep, '' }, run_remote('--remote-expr', 'setline(1, "Yo")'))
|
||||
expect('Yo')
|
||||
end)
|
||||
end)
|
||||
@ -113,7 +129,7 @@ describe('Remote', function()
|
||||
eq(nil, string.find(exec_capture('messages'), 'E247:'))
|
||||
end)
|
||||
|
||||
pending('exits with error on', function()
|
||||
describe('exits with error on', function()
|
||||
local function run_and_check_exit_code(...)
|
||||
local bogus_argv = new_argv(...)
|
||||
|
||||
|
@ -30,7 +30,7 @@ describe(':help', function()
|
||||
eq(1002, funcs.win_getid())
|
||||
end)
|
||||
|
||||
it('multibyte help tags work #23978', function()
|
||||
it('multibyte help tags work #23975', function()
|
||||
mkdir('Xhelptags')
|
||||
finally(function()
|
||||
rmdir('Xhelptags')
|
||||
|
Loading…
Reference in New Issue
Block a user