Skip to content

Commit 7416f3e

Browse files
committed
patch 8.0.0475: not enough testing for the client-server feature
Problem: Not enough testing for the client-server feature. Solution: Add more tests. Add the remote_startserver() function. Fix that a locally evaluated expression uses function-local variables.
1 parent 15bf76d commit 7416f3e

File tree

7 files changed

+73
-22
lines changed

7 files changed

+73
-22
lines changed

runtime/doc/eval.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,6 +2262,8 @@ remote_peek({serverid} [, {retvar}])
22622262
remote_read({serverid}) String read reply string
22632263
remote_send({server}, {string} [, {idvar}])
22642264
String send key sequence
2265+
remote_startserver({name}) none become server {name}
2266+
String send key sequence
22652267
remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
22662268
remove({dict}, {key}) any remove entry {key} from {dict}
22672269
rename({from}, {to}) Number rename (move) file from {from} to {to}
@@ -6372,6 +6374,7 @@ remote_send({server}, {string} [, {idvar}])
63726374
See also |clientserver| |RemoteReply|.
63736375
This function is not available in the |sandbox|.
63746376
{only available when compiled with the |+clientserver| feature}
6377+
63756378
Note: Any errors will be reported in the server and may mess
63766379
up the display.
63776380
Examples: >
@@ -6383,6 +6386,12 @@ remote_send({server}, {string} [, {idvar}])
63836386
:echo remote_send("gvim", ":sleep 10 | echo ".
63846387
\ 'server2client(expand("<client>"), "HELLO")<CR>')
63856388
<
6389+
*remote_startserver()* *E941* *E942*
6390+
remote_startserver({name})
6391+
Become the server {name}. This fails if already running as a
6392+
server, when |v:servername| is not empty.
6393+
{only available when compiled with the |+clientserver| feature}
6394+
63866395
remove({list}, {idx} [, {end}]) *remove()*
63876396
Without {end}: Remove the item at {idx} from |List| {list} and
63886397
return the item.

src/evalfunc.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static void f_remote_foreground(typval_T *argvars, typval_T *rettv);
307307
static void f_remote_peek(typval_T *argvars, typval_T *rettv);
308308
static void f_remote_read(typval_T *argvars, typval_T *rettv);
309309
static void f_remote_send(typval_T *argvars, typval_T *rettv);
310+
static void f_remote_startserver(typval_T *argvars, typval_T *rettv);
310311
static void f_remove(typval_T *argvars, typval_T *rettv);
311312
static void f_rename(typval_T *argvars, typval_T *rettv);
312313
static void f_repeat(typval_T *argvars, typval_T *rettv);
@@ -741,6 +742,7 @@ static struct fst
741742
{"remote_peek", 1, 2, f_remote_peek},
742743
{"remote_read", 1, 1, f_remote_read},
743744
{"remote_send", 2, 3, f_remote_send},
745+
{"remote_startserver", 1, 1, f_remote_startserver},
744746
{"remove", 2, 3, f_remove},
745747
{"rename", 2, 2, f_rename},
746748
{"repeat", 2, 2, f_repeat},
@@ -8487,7 +8489,7 @@ check_connection(void)
84878489
make_connection();
84888490
if (X_DISPLAY == NULL)
84898491
{
8490-
EMSG(_("E240: No connection to Vim server"));
8492+
EMSG(_("E240: No connection to the X server"));
84918493
return FAIL;
84928494
}
84938495
return OK;
@@ -8689,6 +8691,33 @@ f_remote_send(typval_T *argvars UNUSED, typval_T *rettv)
86898691
#endif
86908692
}
86918693

8694+
/*
8695+
* "remote_startserver()" function
8696+
*/
8697+
static void
8698+
f_remote_startserver(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
8699+
{
8700+
#ifdef FEAT_CLIENTSERVER
8701+
char_u *server = get_tv_string_chk(&argvars[0]);
8702+
8703+
if (server == NULL)
8704+
return; /* type error; errmsg already given */
8705+
if (serverName != NULL)
8706+
EMSG(_("E941: already started a server"));
8707+
else
8708+
{
8709+
# ifdef FEAT_X11
8710+
if (check_connection() == OK)
8711+
serverRegisterName(X_DISPLAY, server);
8712+
# else
8713+
serverSetName(server);
8714+
# endif
8715+
}
8716+
#else
8717+
EMSG(_("E942: +clientserver feature not available"));
8718+
#endif
8719+
}
8720+
86928721
/*
86938722
* "remove()" function
86948723
*/

src/if_xcmdsrv.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -399,27 +399,7 @@ serverSendToVim(
399399

400400
/* Execute locally if no display or target is ourselves */
401401
if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0))
402-
{
403-
if (asExpr)
404-
{
405-
char_u *ret;
406-
407-
ret = eval_client_expr_to_string(cmd);
408-
if (result != NULL)
409-
{
410-
if (ret == NULL)
411-
*result = vim_strsave((char_u *)_(e_invexprmsg));
412-
else
413-
*result = ret;
414-
}
415-
else
416-
vim_free(ret);
417-
return ret == NULL ? -1 : 0;
418-
}
419-
else
420-
server_to_input_buf(cmd);
421-
return 0;
422-
}
402+
return sendToLocalVim(cmd, asExpr, result);
423403

424404
/*
425405
* Bind the server name to a communication window.
@@ -800,6 +780,7 @@ serverSendReply(char_u *name, char_u *str)
800780
WaitForReply(void *p)
801781
{
802782
Window *w = (Window *) p;
783+
803784
return ServerReplyFind(*w, SROP_Find) != NULL;
804785
}
805786

src/os_mswin.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,10 @@ serverSendToVim(
24092409
int retcode = 0;
24102410
char_u altname_buf[MAX_PATH];
24112411

2412+
/* Execute locally if no display or target is ourselves */
2413+
if (serverName != NULL && STRICMP(name, serverName) == 0)
2414+
return sendToLocalVim(cmd, asExpr, result);
2415+
24122416
/* If the server name does not end in a digit then we look for an
24132417
* alternate name. e.g. when "name" is GVIM the we may find GVIM2. */
24142418
if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1]))

src/proto/main.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ void time_pop(void *tp);
1111
void time_msg(char *mesg, void *tv_start);
1212
void server_to_input_buf(char_u *str);
1313
char_u *eval_client_expr_to_string(char_u *expr);
14+
int sendToLocalVim(char_u *cmd, int asExpr, char_u **result);
1415
char_u *serverConvert(char_u *client_enc, char_u *data, char_u **tofree);
1516
/* vim: set ft=c : */

src/testdir/test_clientserver.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ func Test_client_server()
3030
call WaitFor('remote_expr("' . name . '", "testvar") == "yes"')
3131
call assert_equal('yes', remote_expr(name, "testvar"))
3232

33+
if has('unix') && has('gui') && !has('gui_running')
34+
" Running in a terminal and the GUI is avaiable: Tell the server to open
35+
" the GUI and check that the remote command still works.
36+
" Need to wait for the GUI to start up, otherwise the send hangs in trying
37+
" to send to the terminal window.
38+
call remote_send(name, ":gui -f\<CR>")
39+
sleep 500m
40+
call remote_send(name, ":let testvar = 'maybe'\<CR>")
41+
call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"')
42+
call assert_equal('maybe', remote_expr(name, "testvar"))
43+
endif
44+
45+
call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
46+
47+
" Expression evaluated locally.
48+
if v:servername == ''
49+
call remote_startserver('MYSELF')
50+
call assert_equal('MYSELF', v:servername)
51+
endif
52+
let g:testvar = 'myself'
53+
call assert_equal('myself', remote_expr(v:servername, 'testvar'))
54+
55+
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
56+
call assert_equal('got it', remote_read(g:myserverid))
57+
3358
call remote_send(name, ":qa!\<CR>")
3459
call WaitFor('job_status(g:job) == "dead"')
3560
if job_status(g:job) != 'dead'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
475,
767769
/**/
768770
474,
769771
/**/

0 commit comments

Comments
 (0)