mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
![github-actions[bot]](/assets/img/avatar_default.png)
feat(server): introduce $NVIM
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").
This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of "Failed to start server" spam in
our test/CI logs:
WARN 2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
WARN 2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0
SOLUTION
------------------------------------------------------------------------
1. Set $NVIM to the parent v:servername, *only* in child processes.
- Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
server init.
4. Open a channel to parent automatically, expose it as v:parent.
Fixes #3118
Fixes #6764
Fixes #9336
Ref https://github.com/neovim/neovim/pull/8247#issuecomment-380275696
Ref #8696
(cherry picked from commit b9d97f5951
)
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
57 lines
1.7 KiB
Lua
57 lines
1.7 KiB
Lua
local helpers = require('test.functional.helpers')(after_each)
|
|
local eq, clear = helpers.eq, helpers.clear
|
|
local missing_provider = helpers.missing_provider
|
|
local command = helpers.command
|
|
local write_file = helpers.write_file
|
|
local eval = helpers.eval
|
|
local retry = helpers.retry
|
|
|
|
do
|
|
clear()
|
|
local reason = missing_provider('node')
|
|
if reason then
|
|
pending(string.format("Missing nodejs host, or nodejs version is too old (%s)", reason), function() end)
|
|
return
|
|
end
|
|
end
|
|
|
|
before_each(function()
|
|
clear()
|
|
end)
|
|
|
|
describe('nodejs host', function()
|
|
teardown(function ()
|
|
os.remove('Xtest-nodejs-hello.js')
|
|
os.remove('Xtest-nodejs-hello-plugin.js')
|
|
end)
|
|
|
|
it('works', function()
|
|
local fname = 'Xtest-nodejs-hello.js'
|
|
write_file(fname, [[
|
|
const neovim = require('neovim');
|
|
const nvim = neovim.attach({socket: process.env.NVIM});
|
|
nvim.command('let g:job_out = "hello"');
|
|
]])
|
|
command('let g:job_id = jobstart(["node", "'..fname..'"])')
|
|
retry(nil, 3000, function() eq('hello', eval('g:job_out')) end)
|
|
end)
|
|
it('plugin works', function()
|
|
local fname = 'Xtest-nodejs-hello-plugin.js'
|
|
write_file(fname, [[
|
|
const neovim = require('neovim');
|
|
const nvim = neovim.attach({socket: process.env.NVIM});
|
|
|
|
class TestPlugin {
|
|
hello() {
|
|
this.nvim.command('let g:job_out = "hello-plugin"');
|
|
}
|
|
}
|
|
const PluginClass = neovim.Plugin(TestPlugin);
|
|
const plugin = new neovim.NvimPlugin(null, PluginClass, nvim);
|
|
plugin.instance.hello();
|
|
]])
|
|
command('let g:job_id = jobstart(["node", "'..fname..'"])')
|
|
retry(nil, 3000, function() eq('hello-plugin', eval('g:job_out')) end)
|
|
end)
|
|
end)
|