Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Denops v7 #344

Merged
merged 99 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
b63030b
:boom: Upgrade supported versions
lambdalisue May 12, 2024
d56dd09
:coffee: Refine deno tasks and CIs
lambdalisue May 12, 2024
5992145
:boom: Use JSR imports instead
lambdalisue May 12, 2024
7c4c342
:memo: Remove deno.land badges
lambdalisue May 12, 2024
19fdc98
:herb: Add test utilities
Milly May 16, 2024
29baee9
:bug: `denops#server#close()` should fires DenopsClosed event
Milly May 16, 2024
d154581
:herb: run test task with `LANG=C` environment
Milly May 25, 2024
0a22d0b
:herb: improve verbose messages on error
Milly May 25, 2024
e8b9630
:herb: add server tests
Milly May 25, 2024
34fd84f
:herb: add `useSharedServer` test helper
Milly May 25, 2024
f175d89
:herb: add plugin/denops.vim tests
Milly May 25, 2024
4e1aabc
:herb: exclude `.coverage/`
Milly May 25, 2024
c5e44c6
:herb: use `using s = stub(...)`
Milly May 26, 2024
1df9d5e
:herb: split test steps of `Host.notify()`
Milly May 26, 2024
98e4a98
:herb: increased default test timeout to 30 seconds
Milly May 26, 2024
9c07ac3
:package: remove unnecessary module version caret `^`
Milly May 26, 2024
61afa34
:herb: fix flaky timing tests refs #354
Milly May 26, 2024
0b970ba
:herb: add `DENOPS_TEST_TIMEOUT` environment
Milly May 26, 2024
8bf1744
:herb: add cli tests
Milly May 26, 2024
f2bdf72
:+1: specify version to `@std/cli`
Milly May 28, 2024
a90a3dd
:+1: Add `denops#interrupt()` function
lambdalisue May 14, 2024
eece2a1
:memo: Add `RECOMMENDED` section to help
lambdalisue Jun 1, 2024
eecadec
:+1: use workerio@4.0.1
Milly Jun 11, 2024
5b5ee96
:+1: only import for cache
Milly Jun 13, 2024
ed3a0e2
:muscle: wrap logics into main() function
Milly Jun 13, 2024
460fc3e
:herb: add tests for worker
Milly Jun 13, 2024
6a2506c
:herb: remove unnecessary `verbose`
Milly May 26, 2024
b43cba9
:+1: terminate worker gracefully
Milly May 26, 2024
48682fc
:herb: prevent error in test helper
Milly Jun 15, 2024
658ecda
:+1: satisfies Service as HostService
Milly Jun 16, 2024
4a4002a
:muscle: define argument parsers in module scope
Milly May 16, 2024
9082561
:+1: change `Host#notify()` to async
Milly Jun 16, 2024
9ff52f3
:+1: `console.*` patch fallback to true console output
Milly May 16, 2024
b32f784
:herb: remove duplicate test step
Milly Jun 17, 2024
0079a63
:muscle: use `PromiseWithResolvers<...>`
Milly Jun 17, 2024
49b9ceb
:muscle: refactor map reference
Milly Jun 17, 2024
1c088c0
:+1: gracefully close service
Milly Jun 18, 2024
88cf743
`undefined` instead `void 0`
Milly Jun 18, 2024
f6a5d74
:herb: fix flaky tests
Milly Jun 18, 2024
80eb0bf
:herb: improve `useSharedServer` helper
Milly Jun 22, 2024
3243b1c
:herb: improve `with*` helpers
Milly Jun 22, 2024
d3da45e
:+1: change `denops#server#start` and `...#stop` to asynchronous
Milly May 16, 2024
a732c4b
:muscle: use internal `DenopsSystem*` events
Milly Jun 30, 2024
5a6f45f
:herb: `useSharedServer` helper returns `addr.host` and `addr.port`
Milly Jun 29, 2024
c419ca7
:herb: `withHost` helper provides current `mode`
Milly Jul 2, 2024
9c5978b
:muscle: use `a:options` instead of script variable
Milly Jul 2, 2024
3ee8a2e
:+1: fix restart behavior
Milly Jul 2, 2024
3c4a84f
:+1: fix reconnect behavior
Milly Jun 29, 2024
e5e697b
:herb: fix flaky tests a bit
Milly Jul 2, 2024
a876bb8
:herb: improve plugin/denops.vim tests
Milly Jul 3, 2024
f4bec25
:bug: no error about `g:denops_server_addr` missing on startup
Milly Jul 3, 2024
6a7f4c8
:herb: add nvim to test target
Milly Jul 3, 2024
7822e5d
:herb: improve `Service` tests
Milly Jul 3, 2024
05a71b5
:herb: move test directories
Milly Jul 3, 2024
7c1d419
:herb: add tests for `denops#plugin#*`
Milly Jul 4, 2024
81f267e
:bug: prevent error on `denops#plugin#check_type()`
Milly Jul 4, 2024
87e4cdc
:herb: ignore `denops#plugin#wait()` test on Mac
Milly Jul 4, 2024
d3d5eb9
:+1: Add plugin unload features
Milly Apr 29, 2024
7c79693
:herb: add script rewrite reload test
Milly Jul 3, 2024
93a4669
:herb: improve test coverage
Milly Jul 6, 2024
6fdb1cf
:+1: fix `Service.waitLoaded()` never resolved
Milly Jul 6, 2024
8070bd5
:+1: do not use `Partial`
Milly Jul 7, 2024
00b0b02
:package: Use @denops/core@7.0.0-pre0 instead
lambdalisue Jul 7, 2024
b83586b
:memo: Use JSR instead of deno.land
lambdalisue Jul 7, 2024
d9c16e8
:+1: remove unused module
Milly Jul 7, 2024
35c5758
:package: Update `@denops/core`
lambdalisue Jul 8, 2024
416255d
:package: Specify versions on testdata
lambdalisue Jul 8, 2024
e19b574
:herb: add host `invoke()` calls 'unload' tests
Milly Jul 7, 2024
583a7bd
:herb: improve `DenopsImpl` tests
Milly Jul 7, 2024
a211913
:herb: add `getVersionOr()` tests
Milly Jul 7, 2024
56e71b5
:herb: improve `Vim` and `Neovim` tests
Milly Jul 8, 2024
8e1b292
:muscle: clarify error handling blocks
Milly Jul 10, 2024
4880b90
:+1: improved multiple calls to `unload()`
Milly Jul 10, 2024
9b27654
:memo: improve `denops#plugin#*` docs
Milly Jul 10, 2024
7c49bb8
:herb: ignore test if `DENOPS_TEST_VERBOSE` env exist
Milly Jul 10, 2024
21c56d2
:+1: no `:message` if delayed message is one line or during test
Milly Jul 10, 2024
43f4fab
:herb: add state-specific tests for `denops#plugin#*`
Milly Jul 10, 2024
655faf9
:bug: fix plugin state
Milly Jul 10, 2024
2bd32a7
:bug: fix `denops#plugin#wait_async()` calls the callback after reloaded
Milly Jul 10, 2024
ae5b002
:coffee: disable strategy.fail-fast and tests needs check
Milly Jul 11, 2024
56da553
:herb: improve tests for `denops#plugin#is_loaded()`
Milly Jul 11, 2024
7d2ef71
:boom: restrict plugin {name} in `denops#plugin#*` methods
Milly Jul 11, 2024
0db258f
:boom: discover only valid name plugins
Milly Jul 11, 2024
5f43628
:boom: delete deprecated `denops#plugin#register()`
Milly Jul 11, 2024
488d330
:muscle: use `denops#_internal#event#emit()` instead `doautocmd`
Milly Jul 11, 2024
30505f1
:package: Use `@denops/core@7.0.0`
lambdalisue Jul 20, 2024
40550fc
:coffee: Refine `update` task
lambdalisue Jul 20, 2024
04f546d
:package: bump @core/unknownutil from 3.18.0 to 3.18.1
lambdalisue Jul 20, 2024
25e01b3
:package: bump @denops/vim-channel-command from 4.0.0 to 4.0.2
lambdalisue Jul 20, 2024
2f9f523
:package: bump @lambdalisue/errorutil from 1.0.0 to 1.1.0
lambdalisue Jul 20, 2024
180d8cd
:package: bump @lambdalisue/workerio from 4.0.0 to 4.0.1
lambdalisue Jul 20, 2024
74f8650
:package: bump @std/assert to 1.0.1
lambdalisue Jul 20, 2024
ddc8956
:package: bump @std/async from 0.224.0 to 1.0.1
lambdalisue Jul 20, 2024
c5b3864
:package: bump @std/cli from 0.224.3 to 1.0.1
lambdalisue Jul 20, 2024
21dcf24
:package: bump @std/path from 0.225.0 to 1.0.2
lambdalisue Jul 20, 2024
211ed2d
:package: bump @std/semver from 0.224.0 to 0.224.3
lambdalisue Jul 20, 2024
41e3d12
:package: bump @std/testing from 0.224.0 to 1.0.0-rc.5
lambdalisue Jul 20, 2024
0a78e35
:package: bump sinon from 17.0.1 to 18.0.0
lambdalisue Jul 20, 2024
6eb990e
:herb: Fix error message in test
lambdalisue Jul 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,58 +41,62 @@ jobs:
run: deno task check

test:
needs: check

strategy:
fail-fast: false
matrix:
runner:
- windows-latest
- macos-latest
- ubuntu-latest
version:
- "1.38.x"
- "1.45.x"
- "1.x"
host_version:
- vim: "v9.0.2189"
nvim: "v0.9.4"
- vim: "v9.1.0448"
nvim: "v0.10.0"

runs-on: ${{ matrix.runner }}

steps:
- run: git config --global core.autocrlf false
if: runner.os == 'Windows'

- uses: actions/checkout@v4

- uses: denoland/setup-deno@v1.1.4
with:
deno-version: "${{ matrix.version }}"

- uses: rhysd/action-setup-vim@v1
id: vim
with:
version: "${{ matrix.host_version.vim }}"
- name: Check Vim
run: |
echo ${DENOPS_TEST_VIM}
${DENOPS_TEST_VIM} --version
env:
DENOPS_TEST_VIM: ${{ steps.vim.outputs.executable }}

- uses: rhysd/action-setup-vim@v1
id: nvim
with:
neovim: true
version: "${{ matrix.host_version.nvim }}"
- name: Check Neovim

- name: Export executables
run: |
echo ${DENOPS_TEST_NVIM}
${DENOPS_TEST_NVIM} --version
env:
DENOPS_TEST_NVIM: ${{ steps.nvim.outputs.executable }}
echo "DENOPS_TEST_VIM_EXECUTABLE=${{ steps.vim.outputs.executable }}" >> "$GITHUB_ENV"
echo "DENOPS_TEST_NVIM_EXECUTABLE=${{ steps.nvim.outputs.executable }}" >> "$GITHUB_ENV"

- name: Perform pre-cache
run: deno cache ./denops/@denops-private/mod.ts

- name: Test
run: deno task test:coverage
env:
DENOPS_TEST_DENOPS_PATH: "./"
DENOPS_TEST_VIM_EXECUTABLE: ${{ steps.vim.outputs.executable }}
DENOPS_TEST_NVIM_EXECUTABLE: ${{ steps.nvim.outputs.executable }}
timeout-minutes: 5
timeout-minutes: 10

- run: |
deno task coverage --lcov > coverage.lcov

- uses: codecov/codecov-action@v4
with:
os: ${{ runner.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
- name: Update dependencies and commit changes
run: deno task -q upgrade:commit --summary ../title.txt --report ../body.md
run: deno task -q update:commit --summary ../title.txt --report ../body.md
- name: Check result
id: result
uses: andstor/file-existence-action@v2
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
<strong>Denops</strong><br>
<sup>An ecosystem for Vim/Neovim enabling developers to write plugins in Deno.</sup>

[![Deno 1.38.5 or above](https://img.shields.io/badge/Deno-Support%201.38.5-yellowgreen.svg?logo=deno)](https://github.com/denoland/deno/tree/v1.38.5)
[![Vim 9.0.2189 or above](https://img.shields.io/badge/Vim-Support%209.0.2189-yellowgreen.svg?logo=vim)](https://github.com/vim/vim/tree/v9.0.2189)
[![Neovim 0.9.4 or above](https://img.shields.io/badge/Neovim-Support%200.9.4-yellowgreen.svg?logo=neovim&logoColor=white)](https://github.com/neovim/neovim/tree/v0.9.4)
[![Deno 1.45.0 or above](https://img.shields.io/badge/Deno-Support%201.45.0-yellowgreen.svg?logo=deno)](https://github.com/denoland/deno/tree/v1.45.0)
[![Vim 9.1.0448 or above](https://img.shields.io/badge/Vim-Support%209.1.0448-yellowgreen.svg?logo=vim)](https://github.com/vim/vim/tree/v9.1.0448)
[![Neovim 0.10.0 or above](https://img.shields.io/badge/Neovim-Support%200.10.0-yellowgreen.svg?logo=neovim&logoColor=white)](https://github.com/neovim/neovim/tree/v0.10.0)

[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x/denops__core-lightgrey.svg?logo=deno)](https://deno.land/x/denops_core)
[![test](https://github.com/vim-denops/denops.vim/actions/workflows/test.yml/badge.svg)](https://github.com/vim-denops/denops.vim/actions/workflows/test.yml)
[![codecov](https://codecov.io/github/vim-denops/denops.vim/branch/main/graph/badge.svg?token=k50SaoYUp0)](https://codecov.io/github/vim-denops/denops.vim)

[![vim help](https://img.shields.io/badge/vim-%3Ah%20denops-orange.svg)](doc/denops.txt)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/denops_core/mod.ts)
[![Documentation](https://img.shields.io/badge/denops-Documentation-yellow.svg)](https://vim-denops.github.io/denops-documentation/)

</div>
Expand Down
8 changes: 8 additions & 0 deletions autoload/denops.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function! denops#request_async(name, method, params, success, failure) abort
\)
endfunction

function! denops#interrupt(...) abort
let l:args = a:0 ? [a:1] : []
call denops#server#wait_async({ -> denops#_internal#server#chan#notify(
\ 'invoke',
\ ['interrupt', l:args],
\)})
endfunction

" Configuration
call denops#_internal#conf#define('denops#disabled', 0)
call denops#_internal#conf#define('denops#deno', 'deno')
Expand Down
4 changes: 3 additions & 1 deletion autoload/denops/_internal/echo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ function! s:echomsg_batch() abort
let s:delayed_timer = 0
let s:delayed_messages = []
" Forcibly show the messages to the user
call feedkeys(printf("\<Cmd>%dmessages\<CR>", l:counter), 'n')
if l:counter > 1 && !g:denops#_test
call feedkeys(printf("\<Cmd>%dmessages\<CR>", l:counter), 'n')
endif
endfunction
3 changes: 3 additions & 0 deletions autoload/denops/_internal/event.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function denops#_internal#event#emit(name) abort
execute 'doautocmd <nomodeline> User' a:name
endfunction
31 changes: 19 additions & 12 deletions autoload/denops/_internal/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ if has('nvim')
\ 'on_stderr': funcref('s:on_recv', [a:options.on_stderr]),
\ 'on_exit': funcref('s:on_exit', [a:options.on_exit]),
\}
return jobstart(a:args, l:options)
try
return jobstart(a:args, l:options)
catch
" NOTE: Call `on_exit` when cmd (args[0]) is not executable.
call timer_start(0, { -> l:options.on_exit(-1, -1, 'exit') })
endtry
endfunction

function! s:stop(job) abort
try
call jobstop(a:job)
call jobwait([a:job])
catch /^Vim\%((\a\+)\)\=:E900/
" NOTE:
" Vim does not raise exception even the job has already closed so fail
Expand Down Expand Up @@ -58,24 +62,27 @@ else
\ 'err_cb': funcref('s:out_cb', [a:options.on_stderr, 'stderr']),
\ 'exit_cb': funcref('s:exit_cb', [a:options.on_exit, 'exit']),
\}
return job_start(a:args, l:options)
let l:job = job_start(a:args, l:options)
if l:job->job_status() ==# "fail"
" NOTE:
" On Windows call `on_exit` when cmd (args[0]) is not executable.
" On Unix a non-existing command results in "dead" instead of "fail",
" and `on_exit` is called by `job_start()`.
call timer_start(0, { -> l:options.exit_cb(-1, -1) })
endif
return l:job
endfunction

function! s:stop(job) abort
call job_stop(a:job)
call timer_start(s:KILL_TIMEOUT_MS, { -> job_stop(a:job, 'kill') })
" Wait until the job is actually closed
while job_status(a:job) ==# 'run'
sleep 10m
endwhile
redraw
endfunction

function! s:out_cb(callback, event, ch, msg) abort
call a:callback(a:ch, a:msg, a:event)
function! s:out_cb(callback, event, job, msg) abort
call a:callback(a:job, a:msg, a:event)
endfunction

function! s:exit_cb(callback, event, ch, status) abort
call a:callback(a:ch, a:status, a:event)
function! s:exit_cb(callback, event, job, status) abort
call a:callback(a:job, a:status, a:event)
endfunction
endif
62 changes: 57 additions & 5 deletions autoload/denops/_internal/plugin.vim
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const s:STATE_RESERVED = 'reserved'
const s:STATE_LOADING = 'loading'
const s:STATE_LOADED = 'loaded'
const s:STATE_UNLOADING = 'unloading'
const s:STATE_FAILED = 'failed'

const s:VALID_NAME_PATTERN = '^[-_0-9a-zA-Z]\+$'

let s:plugins = {}

function! denops#_internal#plugin#is_valid_name(name) abort
return a:name =~# s:VALID_NAME_PATTERN
endfunction

function! denops#_internal#plugin#get(name) abort
if !has_key(s:plugins, a:name)
if !denops#_internal#plugin#is_valid_name(a:name)
throw printf('[denops] Invalid plugin name: %s', a:name)
endif
let s:plugins[a:name] = #{name: a:name, script: '', state: s:STATE_RESERVED, callbacks: []}
endif
return s:plugins[a:name]
Expand All @@ -20,24 +30,41 @@ function! denops#_internal#plugin#load(name, script) abort
const l:script = denops#_internal#path#norm(a:script)
const l:args = [a:name, l:script]
let l:plugin = denops#_internal#plugin#get(a:name)
if l:plugin.state !=# s:STATE_RESERVED && l:plugin.state !=# s:STATE_FAILED
call denops#_internal#echo#debug(printf('already loaded. skip: %s', l:args))
return
endif
let l:plugin.state = s:STATE_LOADING
let l:plugin.script = l:script
let s:plugins[a:name] = l:plugin
call denops#_internal#echo#debug(printf('load plugin: %s', l:args))
call denops#_internal#server#chan#notify('invoke', ['load', l:args])
endfunction

function! denops#_internal#plugin#unload(name) abort
const l:args = [a:name]
let l:plugin = denops#_internal#plugin#get(a:name)
if l:plugin.state ==# s:STATE_LOADED
let l:plugin.state = s:STATE_UNLOADING
endif
call denops#_internal#echo#debug(printf('unload plugin: %s', l:args))
call denops#_internal#server#chan#notify('invoke', ['unload', l:args])
endfunction

function! denops#_internal#plugin#reload(name) abort
const l:args = [a:name]
let l:plugin = denops#_internal#plugin#get(a:name)
let l:plugin.state = s:STATE_LOADING
if l:plugin.state ==# s:STATE_LOADED
let l:plugin.state = s:STATE_UNLOADING
endif
call denops#_internal#echo#debug(printf('reload plugin: %s', l:args))
call denops#_internal#server#chan#notify('invoke', ['reload', l:args])
endfunction

function! s:DenopsSystemPluginPre() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginPre:\zs.*')
execute printf('doautocmd <nomodeline> User DenopsPluginPre:%s', l:name)
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_LOADING
call denops#_internal#event#emit(printf('DenopsPluginPre:%s', l:name))
endfunction

function! s:DenopsSystemPluginPost() abort
Expand All @@ -49,21 +76,46 @@ function! s:DenopsSystemPluginPost() abort
for l:Callback in l:callbacks
call l:Callback()
endfor
execute printf('doautocmd <nomodeline> User DenopsPluginPost:%s', l:name)
call denops#_internal#event#emit(printf('DenopsPluginPost:%s', l:name))
endfunction

function! s:DenopsSystemPluginFail() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginFail:\zs.*')
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_FAILED
let l:plugin.callbacks = []
execute printf('doautocmd <nomodeline> User DenopsPluginFail:%s', l:name)
call denops#_internal#event#emit(printf('DenopsPluginFail:%s', l:name))
endfunction

function! s:DenopsSystemPluginUnloadPre() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginUnloadPre:\zs.*')
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_UNLOADING
call denops#_internal#event#emit(printf('DenopsPluginUnloadPre:%s', l:name))
endfunction

function! s:DenopsSystemPluginUnloadPost() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginUnloadPost:\zs.*')
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_RESERVED
call denops#_internal#event#emit(printf('DenopsPluginUnloadPost:%s', l:name))
endfunction

function! s:DenopsSystemPluginUnloadFail() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginUnloadFail:\zs.*')
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_RESERVED
let l:plugin.callbacks = []
call denops#_internal#event#emit(printf('DenopsPluginUnloadFail:%s', l:name))
endfunction

augroup denops_autoload_plugin_internal
autocmd!
autocmd User DenopsSystemPluginPre:* ++nested call s:DenopsSystemPluginPre()
autocmd User DenopsSystemPluginPost:* ++nested call s:DenopsSystemPluginPost()
autocmd User DenopsSystemPluginFail:* ++nested call s:DenopsSystemPluginFail()
autocmd User DenopsSystemPluginUnloadPre:* ++nested call s:DenopsSystemPluginUnloadPre()
autocmd User DenopsSystemPluginUnloadPost:* ++nested call s:DenopsSystemPluginUnloadPost()
autocmd User DenopsSystemPluginUnloadFail:* ++nested call s:DenopsSystemPluginUnloadFail()
autocmd User DenopsClosed let s:plugins = {}
augroup END
2 changes: 1 addition & 1 deletion autoload/denops/_internal/rpc/nvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endfunction
function! denops#_internal#rpc#nvim#close(chan) abort
call timer_stop(a:chan._healthcheck_timer)
call chanclose(a:chan._id)
call a:chan._on_close(a:chan)
call timer_start(0, { -> a:chan._on_close(a:chan) })
endfunction

function! denops#_internal#rpc#nvim#notify(chan, method, params) abort
Expand Down
17 changes: 11 additions & 6 deletions autoload/denops/_internal/rpc/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ function! denops#_internal#rpc#vim#connect(addr, ...) abort
\ 'on_close': { -> 0 },
\}, a:0 ? a:1 : {},
\)
let l:chan = ch_open(a:addr, {
let l:chan = {
\ '_on_close': l:options.on_close,
\}
let l:chan._handle = ch_open(a:addr, {
\ 'mode': 'json',
\ 'drop': 'auto',
\ 'noblock': 1,
\ 'timeout': g:denops#_internal#rpc#vim#timeout,
\ 'close_cb': l:options.on_close,
\ 'close_cb': { -> l:chan._on_close(l:chan) },
\})
if ch_status(l:chan) !=# 'open'
if ch_status(l:chan._handle) !=# 'open'
throw printf('Failed to connect `%s`', a:addr)
endif
return l:chan
endfunction

function! denops#_internal#rpc#vim#close(chan) abort
return ch_close(a:chan)
" NOTE: 'close_cb' specified on `ch_open` is not invoked when `ch_close` called.
call ch_close(a:chan._handle)
call timer_start(0, { -> a:chan._on_close(a:chan) })
endfunction

function! denops#_internal#rpc#vim#notify(chan, method, params) abort
return ch_sendraw(a:chan, json_encode([0, [a:method] + a:params]) . "\n")
return ch_sendraw(a:chan._handle, json_encode([0, [a:method] + a:params]) . "\n")
endfunction

function! denops#_internal#rpc#vim#request(chan, method, params) abort
let [l:ok, l:err] = ch_evalexpr(a:chan, [a:method] + a:params)
let [l:ok, l:err] = ch_evalexpr(a:chan._handle, [a:method] + a:params)
if l:err isnot# v:null
throw l:err
endif
Expand Down
Loading