Skip to content

Commit

Permalink
Merge pull request #10 from vim-denops/support-v4
Browse files Browse the repository at this point in the history
Support denops v4
  • Loading branch information
lambdalisue authored Jan 19, 2023
2 parents dae08df + 17da1ff commit 11ea193
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
14 changes: 7 additions & 7 deletions autoload/denops_shared_server.vim
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function! denops_shared_server#install() abort
if !exists('g:denops_server_addr')
call denops#util#error('No denops shared server address (g:denops_server_addr) is given.')
call denops_shared_server#util#error('No denops shared server address (g:denops_server_addr) is given.')
return
endif
let [hostname, port] = s:parse_server_addr(g:denops_server_addr)
let options = {
\ 'deno': exepath(g:denops#deno),
\ 'script': denops#util#script_path('@denops-private/cli.ts'),
\ 'script': denops_shared_server#util#script_path('@denops-private/cli.ts'),
\ 'hostname': hostname,
\ 'port': port,
\}
Expand All @@ -17,14 +17,14 @@ function! denops_shared_server#install() abort
elseif executable('systemctl')
call denops_shared_server#systemctl#install(options)
else
call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.')
call denops_shared_server#util#error('This platform is not supported. Please configure denops-shared-server manually.')
return
endif
call denops#util#info('wait 5 second for the shared server startup...')
call denops_shared_server#util#info('wait 5 second for the shared server startup...')
sleep 5
call denops#util#info('connect to the shared server')
call denops_shared_server#util#info('connect to the shared server')
call denops#server#connect()
call denops#util#info('stop the local server')
call denops_shared_server#util#info('stop the local server')
call denops#server#stop()
endfunction

Expand All @@ -36,7 +36,7 @@ function! denops_shared_server#uninstall() abort
elseif executable('systemctl')
call denops_shared_server#systemctl#uninstall()
else
call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.')
call denops_shared_server#util#error('This platform is not supported. Please configure denops-shared-server manually.')
return
endif
endfunction
Expand Down
10 changes: 5 additions & 5 deletions autoload/denops_shared_server/launchctl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ function! denops_shared_server#launchctl#install(options) abort
\ 'deno_args': join(map(copy(g:denops#server#deno_args),
\ { _, val -> printf('<string>%s</string>', val) }), "\n"),
\})
call denops#util#info(printf('create the plist `%s`', s:plist_file))
call denops_shared_server#util#info(printf('create the plist `%s`', s:plist_file))
call mkdir(fnamemodify(s:plist_file, ':h'), 'p')
call writefile(content, s:plist_file, 'b')

call denops#util#info(printf('unload the plist `%s`', s:plist_file))
call denops_shared_server#util#info(printf('unload the plist `%s`', s:plist_file))
call system(printf('launchctl unload %s', s:plist_file))

call denops#util#info(printf('load the plist `%s`', s:plist_file))
call denops_shared_server#util#info(printf('load the plist `%s`', s:plist_file))
echo system(printf('launchctl load -w %s', s:plist_file))
endfunction

function! denops_shared_server#launchctl#uninstall() abort
call denops#util#info(printf('unload the plist `%s`', s:plist_file))
call denops_shared_server#util#info(printf('unload the plist `%s`', s:plist_file))
echo system(printf('launchctl unload %s', s:plist_file))

call denops#util#info(printf('delete the plist `%s`', s:plist_file))
call denops_shared_server#util#info(printf('delete the plist `%s`', s:plist_file))
call delete(s:plist_file)
endfunction
14 changes: 7 additions & 7 deletions autoload/denops_shared_server/runtray.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ function! denops_shared_server#runtray#install(options) abort
\ 'port': a:options.port,
\ 'deno_args': json_encode(g:denops#server#deno_args)[2:-3],
\})
call denops#util#info(printf('create the configuration file `%s`', s:config_file))
call denops_shared_server#util#info(printf('create the configuration file `%s`', s:config_file))
call mkdir(fnamemodify(s:config_file, ':h'), 'p')
call writefile(content, s:config_file, 'b')

call denops#util#info(printf('download the script `%s`', s:script_file))
call denops_shared_server#util#info(printf('download the script `%s`', s:script_file))
call denops_shared_server#runtray#_download_file(s:script_download_url, s:script_file)
call denops_shared_server#runtray#_remove_zone_identifier(s:script_file)

call denops#util#info('install to the startup')
call denops_shared_server#util#info('install to the startup')
call denops_shared_server#runtray#_execute_script_command('install')

call denops#util#info('start the service')
call denops_shared_server#util#info('start the service')
call denops_shared_server#runtray#_execute_script_command('start')
endfunction

function! denops_shared_server#runtray#uninstall() abort
call denops#util#info('uninstall from the startup')
call denops_shared_server#util#info('uninstall from the startup')
call denops_shared_server#runtray#_execute_script_command('uninstall')

call denops#util#info(printf('delete the configuration file `%s`', s:config_file))
call denops_shared_server#util#info(printf('delete the configuration file `%s`', s:config_file))
call delete(s:config_file)

call denops#util#info(printf('delete the script `%s`', s:script_file))
call denops_shared_server#util#info(printf('delete the script `%s`', s:script_file))
call delete(s:script_file)
endfunction

Expand Down
16 changes: 8 additions & 8 deletions autoload/denops_shared_server/systemctl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ function! denops_shared_server#systemctl#install(options) abort
\ 'port': a:options.port,
\ 'deno_args': join(g:denops#server#deno_args, ' '),
\})
call denops#util#info(printf('create the unit file `%s`', s:unit_file))
call denops_shared_server#util#info(printf('create the unit file `%s`', s:unit_file))
call mkdir(fnamemodify(s:unit_file, ':h'), 'p')
call writefile(content, s:unit_file, 'b')

call denops#util#info(printf('enable the unit `%s`', s:name))
call denops_shared_server#util#info(printf('enable the unit `%s`', s:name))
echo system(printf('systemctl --user enable %s.service', s:name))

call denops#util#info(printf('start the unit `%s`', s:name))
call denops_shared_server#util#info(printf('start the unit `%s`', s:name))
echo system(printf('systemctl --user start %s.service', s:name))
endfunction

function! denops_shared_server#systemctl#uninstall() abort
call denops#util#info(printf('stop the unit `%s`', s:name))
call denops_shared_server#util#info(printf('stop the unit `%s`', s:name))
echo system(printf('systemctl --user stop %s.service', s:name))

call denops#util#info(printf('disable the unit `%s`', s:name))
call denops_shared_server#util#info(printf('disable the unit `%s`', s:name))
echo system(printf('systemctl --user disable %s.service', s:name))

call denops#util#info(printf('delete the unit file `%s`', s:unit_file))
call denops_shared_server#util#info(printf('delete the unit file `%s`', s:unit_file))
call delete(s:unit_file)

call denops#util#info('daemon reload')
call denops_shared_server#util#info('daemon reload')
echo system('systemctl --user daemon-reload')

call denops#util#info('reset failed')
call denops_shared_server#util#info('reset failed')
echo system('systemctl --user reset-failed')
endfunction
25 changes: 25 additions & 0 deletions autoload/denops_shared_server/util.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function! denops_shared_server#util#script_path(path) abort
try
" Denops v4 or later
return denops#_internal#path#script([a:path])
catch /^Vim\%((\a\+)\)\=:E117:/
" Denops v3 or prior
return denops#util#script_path(a:path)
endtry
endfunction

function! denops_shared_server#util#info(...) abort
call s:echomsg('None', a:000)
endfunction

function! denops_shared_server#util#error(...) abort
call s:echomsg('ErrorMsg', a:000)
endfunction

function! s:echomsg(hl, msg) abort
execute printf('echohl %s', a:hl)
for l:line in split(join(a:msg), '\n')
echomsg printf('[denops-shared-server] %s', l:line)
endfor
echohl None
endfunction

0 comments on commit 11ea193

Please sign in to comment.