mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
eval: serverstart: Return finalized address to user
In the process of setting up the socket watcher, the address may be changed (e.g., adding the OS-selected port).
This commit is contained in:
parent
3f85c2e43a
commit
6c135b89ee
@ -14296,23 +14296,39 @@ static void f_serverstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *address;
|
||||||
// If the user supplied an address, use it, otherwise use a temp.
|
// If the user supplied an address, use it, otherwise use a temp.
|
||||||
if (argvars[0].v_type != VAR_UNKNOWN) {
|
if (argvars[0].v_type != VAR_UNKNOWN) {
|
||||||
if (argvars[0].v_type != VAR_STRING) {
|
if (argvars[0].v_type != VAR_STRING) {
|
||||||
EMSG(_(e_invarg));
|
EMSG(_(e_invarg));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
rettv->vval.v_string = (char_u *)xstrdup(tv_get_string(argvars));
|
address = xstrdup(tv_get_string(argvars));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rettv->vval.v_string = (char_u *)server_address_new();
|
address = server_address_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = server_start((char *) rettv->vval.v_string);
|
int result = server_start(address);
|
||||||
|
xfree(address);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
EMSG2("Failed to start server: %s",
|
EMSG2("Failed to start server: %s",
|
||||||
result > 0 ? "Unknonwn system error" : uv_strerror(result));
|
result > 0 ? "Unknonwn system error" : uv_strerror(result));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Since it's possible server_start adjusted the given {address} (e.g.,
|
||||||
|
// "localhost:" will now have a port), return the final value to the user.
|
||||||
|
size_t n;
|
||||||
|
char **addrs = server_address_list(&n);
|
||||||
|
rettv->vval.v_string = (char_u *)addrs[n - 1];
|
||||||
|
|
||||||
|
n--;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
xfree(addrs[i]);
|
||||||
|
}
|
||||||
|
xfree(addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "serverstop()" function
|
/// "serverstop()" function
|
||||||
|
@ -62,12 +62,14 @@ describe('serverstart(), serverstop()', function()
|
|||||||
clear_serverlist()
|
clear_serverlist()
|
||||||
eq({}, funcs.serverlist())
|
eq({}, funcs.serverlist())
|
||||||
|
|
||||||
funcs.serverstart('127.0.0.1:0') -- assign random port
|
local s = funcs.serverstart('127.0.0.1:0') -- assign random port
|
||||||
assert(string.match(funcs.serverlist()[1], '127.0.0.1:%d+'))
|
assert(string.match(s, '127.0.0.1:%d+'))
|
||||||
|
eq(s, funcs.serverlist()[1])
|
||||||
clear_serverlist()
|
clear_serverlist()
|
||||||
|
|
||||||
funcs.serverstart('127.0.0.1:') -- assign random port
|
s = funcs.serverstart('127.0.0.1:') -- assign random port
|
||||||
assert(string.match(funcs.serverlist()[1], '127.0.0.1:%d+'))
|
assert(string.match(s, '127.0.0.1:%d+'))
|
||||||
|
eq(s, funcs.serverlist()[1])
|
||||||
clear_serverlist()
|
clear_serverlist()
|
||||||
|
|
||||||
funcs.serverstart('127.0.0.1:12345')
|
funcs.serverstart('127.0.0.1:12345')
|
||||||
|
Loading…
Reference in New Issue
Block a user