Skip to content

Commit

Permalink
Merge pull request #553 from Shougo/yarp
Browse files Browse the repository at this point in the history
Vim8 support using nvim-yarp and vim-hug-neovim-rpc
  • Loading branch information
Shougo committed Oct 22, 2017
2 parents 45f23f1 + 0039ab2 commit 1f074c1
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 111 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

* OS:

* neovim version:
* neovim/Vim version:

* `:CheckHealth` result(neovim ver.0.1.5-452+):
* `:checkhealth` or `:CheckHealth` result(neovim only):

## Provide a minimal init.vim with less than 50 lines (Required!)
## Provide a minimal init.vim/vimrc with less than 50 lines (Required!)

```vim
" Your minimal init.vim
" Your minimal init.vim/vimrc
set runtimepath+=~/path/to/deoplete.nvim/
let g:deoplete#enable_at_startup = 1
```


## The reproduce ways from neovim starting (Required!)
## The reproduce ways from neovim/Vim starting (Required!)

1. foo
2. bar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.py[cod]
doc/tags
vim-themis
.cache
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,63 @@ current buffer.
To view the current options, please consult the
[documentation](https://github.com/Shougo/deoplete.nvim/blob/master/doc%2Fdeoplete.txt).


## Installation

**Note:** deoplete requires Neovim(latest is recommended) with Python3 and
**Note:** deoplete requires Neovim(latest is recommended) or Vim8 with Python3 and
timers(neovim ver.0.1.5+) enabled. See [requirements](#requirements) if you
aren't sure whether you have this.

1. Extract the files and put them in your Neovim directory
1. Extract the files and put them in your Neovim or .vim directory
(usually `$XDG_CONFIG_HOME/nvim/`).
2. Execute the `:UpdateRemotePlugins` and restart Neovim.
3. Write `call deoplete#enable()` or `let g:deoplete#enable_at_startup = 1` in
2. Write `call deoplete#enable()` or `let g:deoplete#enable_at_startup = 1` in
your `init.vim`


For vim-plug

```viml
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
```

For dein.vim

```viml
call dein#add('Shougo/deoplete.nvim')
if !has('nvim')
call dein#add('roxma/nvim-yarp')
call dein#add('roxma/vim-hug-neovim-rpc')
endif
```


## Requirements

deoplete requires Neovim with if\_python3.
deoplete requires Neovim or Vim8 with if\_python3.
If `:echo has("python3")` returns `1`, then you're done; otherwise, see below.

You can enable Python3 interface with pip:

pip3 install neovim

Please install nvim-yarp plugin for Vim8.
https://github.com/roxma/nvim-yarp

Please install vim-hug-neovim-rpc plugin for Vim8.
https://github.com/roxma/vim-hug-neovim-rpc


## Note: Python3 must be enabled before updating remote plugins
If Deoplete was installed prior to Python support being added to Neovim,
`:UpdateRemotePlugins` should be executed manually in order to enable
auto-completion.


## Sources

deoplete will display completions via `complete()` by default.
Expand All @@ -62,10 +84,6 @@ If you want to read the Neovim-python/python3 interface install documentation,
you should read `:help provider-python` and the Wiki.
https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim

## Note: Python3 must be enabled before updating remote plugins
If Deoplete was installed prior to Python support being added to Neovim,
`:UpdateRemotePlugins` should be executed manually in order to enable
auto-completion.

## Screenshots

Expand All @@ -92,6 +110,7 @@ https://www.youtube.com/watch?v=oanoPTpiSF4

[Vim Script completion using neco-vim](https://cloud.githubusercontent.com/assets/3712731/17461000/660e15be-5caf-11e6-8c02-eb9f9c169f3c.gif)


## Configuration Examples

```vim
Expand Down
44 changes: 31 additions & 13 deletions autoload/deoplete/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,48 @@ endfunction
function! deoplete#init#_channel() abort
if !has('timers')
call deoplete#util#print_error(
\ 'deoplete requires Neovim with timers support("+timers").')
\ 'deoplete requires timers support("+timers").')
return 1
endif

try
if !exists('g:loaded_remote_plugins')
runtime! plugin/rplugin.vim
if has('nvim')
call _deoplete_init()
else
let g:deoplete#_yarp = yarp#py3('deoplete')
call g:deoplete#_yarp.notify('deoplete_init')
endif
call _deoplete()
catch
if !has('nvim') || !has('python3')
call deoplete#util#print_error(v:exception)
call deoplete#util#print_error(v:throwpoint)

if !has('python3')
call deoplete#util#print_error(
\ 'deoplete requires Neovim with Python3 support("+python3").')
return 1
\ 'deoplete requires Python3 support("+python3").')
endif

call deoplete#util#print_error(printf(
\ 'deoplete failed to load: %s. '
if has('nvim')
call deoplete#util#print_error(
\ 'deoplete failed to load. '
\ .'Try the :UpdateRemotePlugins command and restart Neovim. '
\ .'See also :CheckHealth.',
\ v:exception))
\ .'See also :CheckHealth.')
else
if !exists('*neovim_rpc#serveraddr')
call deoplete#util#print_error(
\ 'deoplete requires vim-hug-neovim-rpc plugin in Vim.')
endif

if !exists('*yarp#py3')
call deoplete#util#print_error(
\ 'deoplete requires nvim-yarp plugin in Vim.')
endif
endif

return 1
endtry
endfunction
function! deoplete#init#_check_channel() abort
return !exists('g:deoplete#_channel_id')
return !exists('g:deoplete#_initialized')
endfunction
function! deoplete#init#_enable() abort
call deoplete#handler#_init()
Expand Down Expand Up @@ -209,7 +225,9 @@ function! deoplete#init#_context(event, sources) abort
\ 'bufpath': bufpath,
\ 'bufsize': wordcount().bytes,
\ 'cwd': getcwd(),
\ 'vars': filter(copy(g:), "stridx(v:key, 'deoplete#') == 0"),
\ 'vars': filter(copy(g:),
\ "stridx(v:key, 'deoplete#') == 0
\ && v:key !=# 'deoplete#_yarp'"),
\ 'bufvars': filter(copy(b:), "stridx(v:key, 'deoplete_') == 0"),
\ 'custom': deoplete#custom#get(),
\ 'omni__omnifunc': &l:omnifunc,
Expand Down
19 changes: 14 additions & 5 deletions autoload/deoplete/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,32 @@ function! deoplete#util#get_context_filetype(input, event) abort
\ s:context_filetype.filetypes, s:context_filetype.same_filetypes]
endfunction

function! deoplete#util#rpcnotify(...) abort
function! deoplete#util#rpcnotify(event, context) abort
if deoplete#init#_check_channel()
return ''
endif

if !exists('s:logged') && !empty(g:deoplete#_logging)
call rpcnotify(g:deoplete#_channel_id,
\ 'deoplete_enable_logging',
\ g:deoplete#_logging.level, g:deoplete#_logging.logfile)
call s:notify('deoplete_enable_logging',
\ deoplete#init#_context(a:event, []))
let g:deoplete#_logging = {}
let s:logged = 1
endif

call call('rpcnotify', [g:deoplete#_channel_id] + a:000)
call s:notify(a:event, a:context)
return ''
endfunction

function! s:notify(event, context) abort
let a:context['rpc'] = a:event

if has('nvim')
call rpcnotify(g:deoplete#_channel_id, a:event, a:context)
else
call g:deoplete#_yarp.notify(a:event, a:context)
endif
endfunction

" Compare versions. Return values is the distance between versions. Each
" version integer (from right to left) is an ascending power of 100.
"
Expand Down
70 changes: 20 additions & 50 deletions doc/deoplete.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*deoplete.txt* Dark powered asynchronous completion framework for neovim.
*deoplete.txt* Dark powered asynchronous completion framework for neovim/Vim8.

Version: 4.0
Author: Shougo <Shougo.Matsu at gmail.com>
Expand Down Expand Up @@ -44,14 +44,20 @@ Improvements in deoplete in comparison to |neocomplete|:
==============================================================================
INSTALL *deoplete-install*

Note: deoplete requires Neovim(latest is recommended) with Python3 and
Note: deoplete requires Neovim or Vim8(latest is recommended) with Python3 and
|+timers| enabled.

1. Extract the files and put them in your Neovim directory
Please install nvim-yarp plugin for Vim8.
https://github.com/roxma/nvim-yarp

Please install vim-hug-neovim-rpc plugin for Vim8.
https://github.com/roxma/vim-hug-neovim-rpc

1. Extract the files and put them in your Neovim or .vim directory
(usually `$XDG_CONFIG_HOME/nvim/`).
2. Execute the ":UpdateRemotePlugins" and restart Neovim.
3. Call |deoplete#enable()| or set "let g:deoplete#enable_at_startup = 1" in
2. Call |deoplete#enable()| or set "let g:deoplete#enable_at_startup = 1" in
your `init.vim`
3. Execute the ":UpdateRemotePlugins" if Neovim.

If ":echo has('python3')" returns `1`, then you're done; otherwise, see below.

Expand Down Expand Up @@ -1214,47 +1220,6 @@ https://github.com/shawncplus/phpcomplete.vim
phpcd.vim: another PHP omnifunc. Faster.
https://github.com/php-vim/phpcd.vim

==============================================================================
VIM8 ASYNC API SUPPORT *deoplete-vim8*

Current deoplete does not support Vim8 asynchronous API.
To support Vim8, neovim-python compatible API is needed.
I have not plan to create it.
But if it is created, I will support it.

Q: Why neovim-python compatible API is needed? Vim8 already implements
asynchronous API. It optimize your plugins, doesn't it?
Q: Why neocomplete/unite.vim does not support Vim8 asynchronous API?

A: Vim8 asynchronous API (or neovim job API) does replace vimproc plugin.
No more vimproc dependency. But it does not optimize my plugins.
To optimize my plugins, I must rewrite the plugins and most functions must be
executed in the separated process. It is hard way though, it is already done.
Yes, it is deoplete!

Q: Why does not use the external interfaces?

A: Current all external interfaces block your Vim. The neovim remote plugin
feature is not.

Q: Why neovim remote plugin is better?

A: It is the separated process and easy to communicate with Vim like the
external interfaces. I think it is the killer feature in neovim. It is not
well known though.

Q: neovim-python compatible API can be implemented by Vim8 async API?

A: Yes. Vim8 implements JSON RPC. I think you can create Python-Vim
input/output interface using JSON RPC. It is like MessagePack-RPC in neovim.

Q: Why don't you implement neovim-python compatibility API using Vim8 JSON
RPC?

A: I have not much time. You can implement it. Why do I need to implement
the feature? neovim remote plugin feature already works! It should be
implemented by needed person.

==============================================================================
FREQUENTLY ASKED QUESTIONS (FAQ) *deoplete-faq*

Expand All @@ -1273,15 +1238,20 @@ A: 1. Please update neovim to the latest version.
$ sudo pip3 install neovim --upgrade
<
3. Please execute ":UpdateRemotePlugins" or ":NeoBundleRemotePlugins" (for
using NeoBundle) command manually.
3. Please execute ":UpdateRemotePlugins" command manually if Neovim.

4. Please install nvim-yarp plugin for Vim8.
https://github.com/roxma/nvim-yarp

5. Please install vim-hug-neovim-rpc plugin for Vim8.
https://github.com/roxma/vim-hug-neovim-rpc

4. Please check if Python3 interface works. You can check it by the command
6. Please check if Python3 interface works. You can check it by the command
`:echo has('python3')` .

https://github.com/neovim/neovim/wiki/Troubleshooting#python-support-isnt-working

5. Please enable debug mode from command line and upload the log file. >
7. Please enable debug mode from command line and upload the log file. >
$ export NVIM_PYTHON_LOG_FILE=/tmp/log
$ export NVIM_PYTHON_LOG_LEVEL=DEBUG
Expand Down
9 changes: 8 additions & 1 deletion plugin/deoplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ let g:loaded_deoplete = 1

" Global options definition.
if get(g:, 'deoplete#enable_at_startup', 0)
call deoplete#enable()
if has('vim_starting')
augroup deoplete
autocmd!
autocmd VimEnter * call deoplete#enable()
augroup END
else
call deoplete#enable()
endif
endif
Loading

0 comments on commit 1f074c1

Please sign in to comment.