diff options
author | James McCoy <jamessan@jamessan.com> | 2017-07-24 10:27:22 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-07-24 20:10:28 -0400 |
commit | 58d8d91ec16b9f7eb3ea31ecae73c6c374e9b847 (patch) | |
tree | ac3037d873dc3d3b7c3592ebe05ad071cd0f013f | |
parent | 5a0acd09c106fb3cee4243aa366ee1eff04776fd (diff) | |
download | rneovim-58d8d91ec16b9f7eb3ea31ecae73c6c374e9b847.tar.gz rneovim-58d8d91ec16b9f7eb3ea31ecae73c6c374e9b847.tar.bz2 rneovim-58d8d91ec16b9f7eb3ea31ecae73c6c374e9b847.zip |
provider: Extra pythonx's stderr handling to common functions
-rw-r--r-- | runtime/autoload/provider.vim | 18 | ||||
-rw-r--r-- | runtime/autoload/provider/pythonx.vim | 16 |
2 files changed, 22 insertions, 12 deletions
diff --git a/runtime/autoload/provider.vim b/runtime/autoload/provider.vim new file mode 100644 index 0000000000..a4d5241b57 --- /dev/null +++ b/runtime/autoload/provider.vim @@ -0,0 +1,18 @@ +" Common functionality for providers + +let s:stderr = {} + +function! provider#stderr_collector(chan_id, data, event) dict + let stderr = get(s:stderr, a:chan_id, ['']) + let stderr[-1] .= a:data[0] + call extend(stderr, a:data[1:]) + let s:stderr[a:chan_id] = stderr +endfunction + +function! provider#clear_stderr(chan_id) + silent! call delete(s:stderr, a:chan_id) +endfunction + +function! provider#get_stderr(chan_id) + return get(s:stderr, a:chan_id, []) +endfunction diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim index 2f64c22c71..7285ed43ea 100644 --- a/runtime/autoload/provider/pythonx.vim +++ b/runtime/autoload/provider/pythonx.vim @@ -5,17 +5,7 @@ endif let s:loaded_pythonx_provider = 1 -let s:stderr = {} -let s:job_opts = {'rpc': v:true} - -" TODO(bfredl): this logic is common and should be builtin -function! s:job_opts.on_stderr(chan_id, data, event) - let stderr = get(s:stderr, a:chan_id, ['']) - let last = remove(stderr, -1) - let a:data[0] = last.a:data[0] - call extend(stderr, a:data) - let s:stderr[a:chan_id] = stderr -endfunction +let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')} function! provider#pythonx#Require(host) abort let ver = (a:host.orig_name ==# 'python') ? 2 : 3 @@ -38,9 +28,11 @@ function! provider#pythonx#Require(host) abort catch echomsg v:throwpoint echomsg v:exception - for row in get(s:stderr, channel_id, []) + for row in provider#get_stderr(channel_id) echomsg row endfor + finally + call provider#clear_stderr(channel_id) endtry throw remote#host#LoadErrorForHost(a:host.orig_name, \ '$NVIM_PYTHON_LOG_FILE') |