mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
serverstop(): return FALSE for invalid address
This commit is contained in:
parent
b11b681289
commit
9f598e5765
37
man/nvim.1
37
man/nvim.1
@ -25,7 +25,7 @@ To enter commands in
|
||||
type a colon
|
||||
.Pq Sq \&:
|
||||
which is also used in this manual to denote commands.
|
||||
For more information, consult the on-line help system with the
|
||||
For more information, consult the online help system with the
|
||||
.Ic :help
|
||||
command.
|
||||
.Bl -tag -width Fl
|
||||
@ -337,12 +337,12 @@ Print version information and exit.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width Fl
|
||||
.It Ev VIM
|
||||
Used to locate various user files, such as the user's init.vim.
|
||||
Used to locate various user files, such as init.vim.
|
||||
.It Ev VIMRUNTIME
|
||||
Used to locate run time files, such as on-line documentation and
|
||||
Used to locate runtime files, such as online documentation and
|
||||
syntax highlighting definitions.
|
||||
.It Ev XDG_CONFIG_HOME
|
||||
Path to use for the user-local configuration directory, see
|
||||
Path to the user-local configuration directory, see
|
||||
.Sx FILES .
|
||||
Defaults to
|
||||
.Pa ~/.config
|
||||
@ -356,7 +356,7 @@ Defaults to
|
||||
.Pa ~/.local/share
|
||||
if not set.
|
||||
.It Ev VIMINIT
|
||||
A string of Ex commands to be executed at startup.
|
||||
Ex commands to be executed at startup.
|
||||
For example, the command to quit is
|
||||
.Ic :q ,
|
||||
so to have
|
||||
@ -375,41 +375,32 @@ command.
|
||||
.Sh FILES
|
||||
.Bl -tag -width "~/.config/nvim/init.vim"
|
||||
.It Pa ~/.config/nvim/init.vim
|
||||
The user-local
|
||||
User-local
|
||||
.Nm
|
||||
configuration file.
|
||||
See
|
||||
.Ev XDG_CONFIG_HOME
|
||||
above.
|
||||
.It Pa ~/.config/nvim
|
||||
The user-local
|
||||
User-local
|
||||
.Nm
|
||||
configuration directory.
|
||||
See
|
||||
.Ev XDG_CONFIG_HOME
|
||||
above.
|
||||
See also
|
||||
.Ev XDG_CONFIG_HOME .
|
||||
.It Pa $VIM/sysinit.vim
|
||||
The system-global
|
||||
System-global
|
||||
.Nm
|
||||
configuration file.
|
||||
.It Pa /usr/local/share/nvim
|
||||
The system-global
|
||||
System-global
|
||||
.Nm
|
||||
runtime directory.
|
||||
.El
|
||||
.Sh AUTHORS
|
||||
.Nm
|
||||
was started by
|
||||
.An Thiago de Arruda ,
|
||||
with a lot of help from others.
|
||||
.Pp
|
||||
Nvim was started by
|
||||
.An Thiago de Arruda .
|
||||
Most of Vim was written by
|
||||
.An -nosplit
|
||||
.An Bram Moolenaar ,
|
||||
with a lot of help from others.
|
||||
.An Bram Moolenaar .
|
||||
See
|
||||
.Ic :help credits .
|
||||
.Pp
|
||||
Vim is based on Stevie, worked on by
|
||||
.An Tim Thompson ,
|
||||
.An Tony Andrews ,
|
||||
|
@ -1789,8 +1789,10 @@ v:scrollstart String describing the script or function that caused the
|
||||
|
||||
*v:servername* *servername-variable*
|
||||
*$NVIM_LISTEN_ADDRESS*
|
||||
v:servername Default Nvim server address. Equivalent to
|
||||
|$NVIM_LISTEN_ADDRESS| on startup. |serverstop()|
|
||||
v:servername Primary listen address of the current Nvim instance, the first
|
||||
item returned by |serverlist()|. Can be set by
|
||||
|--listen| or |$NVIM_LISTEN_ADDRESS| on startup.
|
||||
See also |serverstart()| and |serverstop()|.
|
||||
Read-only.
|
||||
|
||||
|
||||
@ -6638,15 +6640,11 @@ server2client({clientid}, {string}) *server2client()*
|
||||
:echo server2client(expand("<client>"), "HELLO")
|
||||
<
|
||||
serverlist() *serverlist()*
|
||||
Returns a list of available server names in a list.
|
||||
When there are no servers an empty string is returned.
|
||||
Returns a list of server addresses, or empty if all servers
|
||||
were stopped. |serverstart()| |serverstop()|
|
||||
Example: >
|
||||
:echo serverlist()
|
||||
< {Nvim} *--serverlist*
|
||||
The Vim command-line option `--serverlist` was removed from
|
||||
Nvim, but it can be imitated: >
|
||||
nvim --cmd "echo serverlist()" --cmd "q"
|
||||
<
|
||||
|
||||
serverstart([{address}]) *serverstart()*
|
||||
Opens a socket or named pipe at {address} and listens for
|
||||
|RPC| messages. Clients can send |API| commands to the address
|
||||
@ -6674,13 +6672,9 @@ serverstart([{address}]) *serverstart()*
|
||||
|
||||
< |$NVIM_LISTEN_ADDRESS| is set to {address} if not already set.
|
||||
|
||||
*--servername*
|
||||
The Vim command-line option `--servername` can be imitated: >
|
||||
nvim --cmd "let g:server_addr = serverstart('foo')"
|
||||
<
|
||||
serverstop({address}) *serverstop()*
|
||||
Closes the pipe or socket at {address}. Does nothing if
|
||||
{address} is empty or invalid.
|
||||
Closes the pipe or socket at {address}.
|
||||
Returns TRUE if {address} is valid, else FALSE.
|
||||
If |$NVIM_LISTEN_ADDRESS| is stopped it is unset.
|
||||
If |v:servername| is stopped it is set to the next available
|
||||
address returned by |serverlist()|.
|
||||
|
@ -14403,8 +14403,11 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
return;
|
||||
}
|
||||
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
rettv->vval.v_number = 0;
|
||||
if (argvars[0].vval.v_string) {
|
||||
server_stop((char *) argvars[0].vval.v_string);
|
||||
bool rv = server_stop((char *)argvars[0].vval.v_string);
|
||||
rettv->vval.v_number = (rv ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ int server_start(const char *endpoint)
|
||||
/// Stops listening on the address specified by `endpoint`.
|
||||
///
|
||||
/// @param endpoint Address of the server.
|
||||
void server_stop(char *endpoint)
|
||||
bool server_stop(char *endpoint)
|
||||
{
|
||||
SocketWatcher *watcher;
|
||||
bool watcher_found = false;
|
||||
@ -196,8 +196,8 @@ void server_stop(char *endpoint)
|
||||
}
|
||||
|
||||
if (!watcher_found) {
|
||||
ELOG("Not listening on %s", addr);
|
||||
return;
|
||||
WLOG("Not listening on %s", addr);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unset $NVIM_LISTEN_ADDRESS if it is the stopped address.
|
||||
@ -219,6 +219,8 @@ void server_stop(char *endpoint)
|
||||
if (STRCMP(addr, get_vim_var_str(VV_SEND_SERVER)) == 0) {
|
||||
set_vservername(&watchers);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns an allocated array of server addresses.
|
||||
|
@ -11,21 +11,21 @@ local function clear_serverlist()
|
||||
end
|
||||
end
|
||||
|
||||
describe('serverstart(), serverstop()', function()
|
||||
describe('server', function()
|
||||
before_each(clear)
|
||||
|
||||
it('sets $NVIM_LISTEN_ADDRESS on first invocation', function()
|
||||
it('serverstart() sets $NVIM_LISTEN_ADDRESS on first invocation', function()
|
||||
-- Unset $NVIM_LISTEN_ADDRESS
|
||||
command('let $NVIM_LISTEN_ADDRESS = ""')
|
||||
|
||||
local s = eval('serverstart()')
|
||||
assert(s ~= nil and s:len() > 0, "serverstart() returned empty")
|
||||
eq(s, eval('$NVIM_LISTEN_ADDRESS'))
|
||||
command("call serverstop('"..s.."')")
|
||||
eq(1, eval("serverstop('"..s.."')"))
|
||||
eq('', eval('$NVIM_LISTEN_ADDRESS'))
|
||||
end)
|
||||
|
||||
it('sets v:servername _only_ on nvim startup unless all servers are stopped',
|
||||
it('serverstart() sets v:servername at startup or if all servers were stopped',
|
||||
function()
|
||||
local initial_server = meths.get_vvar('servername')
|
||||
assert(initial_server ~= nil and initial_server:len() > 0,
|
||||
@ -38,11 +38,11 @@ describe('serverstart(), serverstop()', function()
|
||||
neq(initial_server, s)
|
||||
|
||||
-- serverstop() does _not_ modify v:servername...
|
||||
funcs.serverstop(s)
|
||||
eq(1, funcs.serverstop(s))
|
||||
eq(initial_server, meths.get_vvar('servername'))
|
||||
|
||||
-- ...unless we stop _all_ servers.
|
||||
funcs.serverstop(funcs.serverlist()[1])
|
||||
eq(1, funcs.serverstop(funcs.serverlist()[1]))
|
||||
eq('', meths.get_vvar('servername'))
|
||||
|
||||
-- v:servername will take the next available server.
|
||||
@ -53,9 +53,9 @@ describe('serverstart(), serverstop()', function()
|
||||
eq(servername, meths.get_vvar('servername'))
|
||||
end)
|
||||
|
||||
it('serverstop() ignores invalid input', function()
|
||||
command("call serverstop('')")
|
||||
command("call serverstop('bogus-socket-name')")
|
||||
it('serverstop() returns false for invalid input', function()
|
||||
eq(0, eval("serverstop('')"))
|
||||
eq(0, eval("serverstop('bogus-socket-name')"))
|
||||
end)
|
||||
|
||||
it('parses endpoints correctly', function()
|
||||
@ -120,7 +120,7 @@ describe('serverlist()', function()
|
||||
-- The new servers should be at the end of the list.
|
||||
for i = 1, #servs do
|
||||
eq(servs[i], new_servs[i + n])
|
||||
command("call serverstop('"..servs[i].."')")
|
||||
eq(1, eval("serverstop('"..servs[i].."')"))
|
||||
end
|
||||
-- After serverstop() the servers should NOT be in the list.
|
||||
eq(n, eval('len(serverlist())'))
|
||||
|
Loading…
Reference in New Issue
Block a user