|
| 1 | +function! denops_shared_server#install() abort |
| 2 | + if !exists('g:denops_server_addr') |
| 3 | + call denops#util#error('No denops shared server address (g:denops_server_addr) is given.') |
| 4 | + return |
| 5 | + endif |
| 6 | + let [hostname, port] = s:parse_server_addr(g:denops_server_addr) |
| 7 | + let options = { |
| 8 | + \ 'deno': exepath(g:denops#deno), |
| 9 | + \ 'script': denops#util#script_path('@denops-private/cli.ts'), |
| 10 | + \ 'hostname': hostname, |
| 11 | + \ 'port': port, |
| 12 | + \} |
| 13 | + if executable('launchctl') |
| 14 | + call denops_shared_server#launchctl#install(options) |
| 15 | + elseif executable('systemctl') |
| 16 | + call denops_shared_server#systemctl#install(options) |
| 17 | + elseif has('win32') |
| 18 | + call denops_shared_server#winsw#install(options) |
| 19 | + else |
| 20 | + call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.') |
| 21 | + return |
| 22 | + endif |
| 23 | + call denops#util#info('wait 1 second for the shared server startup...') |
| 24 | + sleep 1 |
| 25 | + call denops#util#info('connect to the shared server') |
| 26 | + call denops#server#connect() |
| 27 | + call denops#util#info('stop the local server') |
| 28 | + call denops#server#stop() |
| 29 | +endfunction |
| 30 | + |
| 31 | +function! denops_shared_server#uninstall() abort |
| 32 | + if executable('launchctl') |
| 33 | + call denops_shared_server#launchctl#uninstall() |
| 34 | + elseif executable('systemctl') |
| 35 | + call denops_shared_server#systemctl#uninstall() |
| 36 | + elseif has('win32') |
| 37 | + call denops_shared_server#winsw#uninstall() |
| 38 | + else |
| 39 | + call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.') |
| 40 | + return |
| 41 | + endif |
| 42 | +endfunction |
| 43 | + |
| 44 | +function! denops_shared_server#_render(template, context) abort |
| 45 | + let content = join(a:template, "\n") |
| 46 | + for [key, value] in items(a:context) |
| 47 | + let content = substitute(content, printf('{{%s}}', key), escape(value, '\'), 'g') |
| 48 | + endfor |
| 49 | + return split(content, "\n", v:true) |
| 50 | +endfunction |
| 51 | + |
| 52 | +function! s:parse_server_addr(addr) abort |
| 53 | + let parts = split(a:addr, ':', v:true) |
| 54 | + if len(parts) isnot# 2 |
| 55 | + throw printf('[denops-shared-server] Server address must follow `{hostname}:{port}` format but `%s` is given', a:addr) |
| 56 | + endif |
| 57 | + return [parts[0], parts[1]] |
| 58 | +endfunction |
0 commit comments