0
0
mirror of https://github.com/vim/vim.git synced 2025-10-26 09:14:23 -04:00

patch 9.1.1651: Cannot use clientserver over socket

Problem:  Cannot use clientserver over Unix domain socket
Solution: Implement socketserver functionality (Foxe Chen).

fixes: #3509
closes: #17839

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Foxe Chen
2025-08-18 21:40:40 +02:00
committed by Christian Brabandt
parent 31170af24a
commit 96b2154b73
34 changed files with 2562 additions and 68 deletions

View File

@@ -10,6 +10,12 @@ CheckFeature clientserver
source util/shared.vim
" Unlike X11, we need the socket server running if we want to send commands to
" a server via sockets.
if v:servername == ""
call remote_startserver('VIMSOCKETSERVERTEST')
endif
func Check_X11_Connection()
if has('x11')
CheckX11
@@ -184,10 +190,18 @@ func Test_client_server()
call assert_fails('call remote_startserver("")', 'E1175:')
call assert_fails('call remote_startserver([])', 'E1174:')
call assert_fails("let x = remote_peek([])", 'E730:')
call assert_fails("let x = remote_read('vim10')",
\ has('unix') ? ['E573:.*vim10'] : 'E277:')
call assert_fails("call server2client('abc', 'xyz')",
\ has('unix') ? ['E573:.*abc'] : 'E258:')
" When using socket server, server id is not a number, but the path to the
" socket.
if has('socketserver') && !has('X11')
call assert_fails("let x = remote_read('vim/10')", ['E573:.*vim/10'])
call assert_fails("call server2client('a/b/c', 'xyz')", ['E573:.*a/b/c'])
else
call assert_fails("let x = remote_read('vim10')",
\ has('unix') ? ['E573:.*vim10'] : 'E277:')
call assert_fails("call server2client('abc', 'xyz')",
\ has('unix') ? ['E573:.*abc'] : 'E258:')
endif
endfunc
func Test_client_server_stopinsert()
@@ -231,6 +245,121 @@ func Test_client_server_stopinsert()
endtry
endfunc
" Test if socket server and X11 backends can be chosen and work properly.
func Test_client_server_x11_and_socket_server()
CheckNotMSWindows
CheckFeature socketserver
CheckFeature x11
let g:test_is_flaky = 1
let cmd = GetVimCommand()
if cmd == ''
throw 'GetVimCommand() failed'
endif
call Check_X11_Connection()
let types = ['socket', 'x11']
for type in types
let name = 'VIMTEST_' .. toupper(type)
let actual_cmd = cmd .. ' --clientserver ' .. type
let actual_cmd .= ' --servername ' .. name
let job = job_start(actual_cmd, {'stoponexit': 'kill', 'out_io': 'null'})
call WaitForAssert({-> assert_equal("run", job_status(job))})
call WaitForAssert({-> assert_match(name, system(cmd .. ' --clientserver ' .. type .. ' --serverlist'))})
call assert_match(name, system(actual_cmd .. ' --remote-expr "v:servername"'))
call system(actual_cmd .. " --remote-expr 'execute(\"qa!\")'")
try
call WaitForAssert({-> assert_equal("dead", job_status(job))})
finally
if job_status(job) != 'dead'
call assert_report('Server did not exit')
call job_stop(job, 'kill')
endif
endtry
endfor
endfunc
" Test if socket server works in the GUI
func Test_client_socket_server_server_gui()
CheckNotMSWindows
CheckFeature socketserver
CheckFeature gui_gtk
let g:test_is_flaky = 1
let cmd = GetVimCommand()
if cmd == ''
throw 'GetVimCommand() failed'
endif
call Check_X11_Connection()
let name = 'VIMTESTSOCKET'
let cmd .= ' --clientserver socket'
let cmd .= ' --servername ' .. name
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
call WaitForAssert({-> assert_equal("run", job_status(job))})
call WaitForAssert({-> assert_match(name, system(cmd .. ' --serverlist'))})
call system(cmd .. " --remote-expr 'execute(\"gui\")'")
call assert_match('1', system(cmd .. " --remote-expr 'has(\"gui_running\")'"))
call assert_match(name, system(cmd .. ' --remote-expr "v:servername"'))
call system(cmd .. " --remote-expr 'execute(\"qa!\")'")
try
call WaitForAssert({-> assert_equal("dead", job_status(job))})
finally
if job_status(job) != 'dead'
call assert_report('Server did not exit')
call job_stop(job, 'kill')
endif
endtry
endfunc
" Test if custom paths work for socketserver
func Test_client_socket_server_custom_path()
CheckNotMSWindows
CheckFeature socketserver
CheckNotFeature x11
let g:test_is_flaky = 1
let cmd = GetVimCommand()
if cmd == ''
throw 'GetVimCommand() failed'
endif
let name = 'VIMTESTSOCKET2'
let paths = ['./' .. name, '../testdir/' .. name, getcwd(-1) .. '/' .. name]
for path in paths
let actual = cmd .. ' --servername ' .. path
let job = job_start(actual, {'stoponexit': 'kill', 'out_io': 'null'})
call WaitForAssert({-> assert_equal("run", job_status(job))})
call WaitForAssert({-> assert_equal(path, glob(path))})
call system(actual .. " --remote-expr 'execute(\"qa!\")'")
try
call WaitForAssert({-> assert_equal("dead", job_status(job))})
finally
if job_status(job) != 'dead'
call assert_report('Server did not exit')
call job_stop(job, 'kill')
endif
endtry
endfor
endfunc
" Uncomment this line to get a debugging log
" call ch_logfile('channellog', 'w')

View File

@@ -3,6 +3,11 @@
source util/screendump.vim
import './util/vim9.vim' as v9
" Socket backend for remote functions require the socket server to be running
if v:servername == ""
call remote_startserver('VIMSOCKETSERVERTEST')
endif
" Test for passing too many or too few arguments to builtin functions
func Test_internalfunc_arg_error()
let l =<< trim END

View File

@@ -79,6 +79,10 @@ func Test_wayland_startup()
call s:PreTest()
call s:CheckXConnection()
if v:servername == ""
call remote_startserver('VIMSOCKETSERVER')
endif
let l:name = 'WLVIMTEST'
let l:cmd = GetVimCommand() .. ' --servername ' .. l:name
let l:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
@@ -372,6 +376,10 @@ func Test_wayland_autoselect_works()
call writefile(l:lines, 'Wltester', 'D')
if v:servername == ""
call remote_startserver('VIMSOCKETSERVER')
endif
let l:name = 'WLVIMTEST'
let l:cmd = GetVimCommand() .. ' -S Wltester --servername ' .. l:name
let l:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
@@ -415,6 +423,10 @@ func Test_no_wayland_connect_cmd_flag()
call s:PreTest()
call s:CheckXConnection()
if v:servername == ""
call remote_startserver('VIMSOCKETSERVER')
endif
let l:name = 'WLFLAGVIMTEST'
let l:cmd = GetVimCommand() .. ' -Y --servername ' .. l:name
let l:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
@@ -453,6 +465,10 @@ func Test_wayland_become_inactive()
call s:PreTest()
call s:CheckXConnection()
if v:servername == ""
call remote_startserver('VIMSOCKETSERVER')
endif
let l:name = 'WLLOSEVIMTEST'
let l:cmd = GetVimCommand() .. ' --servername ' .. l:name
let l:job = job_start(cmd, {
@@ -544,6 +560,10 @@ func Test_wayland_bad_environment()
let l:old = $XDG_RUNTIME_DIR
unlet $XDG_RUNTIME_DIR
if v:servername == ""
call remote_startserver('VIMSOCKETSERVER')
endif
let l:name = 'WLVIMTEST'
let l:cmd = GetVimCommand() .. ' --servername ' .. l:name
let l:job = job_start(cmd, {