summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2017-06-24 16:52:36 +0900
committerShougo Matsushita <Shougo.Matsu@gmail.com>2017-06-24 16:53:49 +0900
commitcfa6ab803e0b714c4ab6cd8372f51824454a12f1 (patch)
treee37343b511193414a93702b92ee1248228d264cd
parent49362f71d6dea30549db2f145a53ca672046b9af (diff)
downloaddeoplete.nvim-cfa6ab803e0b714c4ab6cd8372f51824454a12f1.zip
Improve the initialization
-rw-r--r--autoload/deoplete/handler.vim10
-rw-r--r--autoload/deoplete/init.vim14
-rw-r--r--autoload/deoplete/mapping.vim3
-rw-r--r--rplugin/python3/deoplete/__init__.py29
-rw-r--r--rplugin/python3/deoplete/deoplete.py5
5 files changed, 24 insertions, 37 deletions
diff --git a/autoload/deoplete/handler.vim b/autoload/deoplete/handler.vim
index b0aa031..2e3a052 100644
--- a/autoload/deoplete/handler.vim
+++ b/autoload/deoplete/handler.vim
@@ -23,8 +23,6 @@ function! deoplete#handler#_init() abort
if g:deoplete#enable_refresh_always
autocmd deoplete InsertCharPre * call s:completion_begin('InsertCharPre')
endif
-
- call s:on_event('Init')
endfunction
function! s:do_complete(timer) abort
@@ -114,6 +112,10 @@ function! s:completion_async(timer) abort
endfunction
function! s:completion_begin(event) abort
+ if !exists('g:deoplete#_initialized')
+ return
+ endif
+
let context = deoplete#init#_context(a:event, [])
if s:is_skip(a:event, context)
call deoplete#mapping#_restore_completeopt()
@@ -189,6 +191,10 @@ function! s:is_skip_text(event) abort
endfunction
function! s:on_event(event) abort
+ if !exists('g:deoplete#_initialized')
+ return
+ endif
+
let context = deoplete#init#_context(a:event, [])
call rpcnotify(g:deoplete#_channel_id, 'deoplete_on_event', context)
endfunction
diff --git a/autoload/deoplete/init.vim b/autoload/deoplete/init.vim
index 7f12b16..27eff1f 100644
--- a/autoload/deoplete/init.vim
+++ b/autoload/deoplete/init.vim
@@ -62,19 +62,7 @@ function! deoplete#init#_channel() abort
return 1
endtry
- " neovim module version check.
- if empty(g:deoplete#_neovim_python_version) ||
- \ empty(filter(copy(g:deoplete#_neovim_python_version),
- \ "deoplete#util#versioncmp(v:val, '0.1.8') >= 0"))
- call deoplete#util#print_error(
- \ 'Current neovim-python module version: ' .
- \ string(g:deoplete#_neovim_python_version))
- call deoplete#util#print_error(
- \ 'deoplete.nvim requires neovim-python 0.1.8+.')
- call deoplete#util#print_error(
- \ 'Please update neovim-python by "pip3 install --upgrade neovim"')
- return 1
- endif
+ call rpcnotify(g:deoplete#_channel_id, 'deoplete_init')
endfunction
function! deoplete#init#_enable() abort
call deoplete#handler#_init()
diff --git a/autoload/deoplete/mapping.vim b/autoload/deoplete/mapping.vim
index e820a85..39dee36 100644
--- a/autoload/deoplete/mapping.vim
+++ b/autoload/deoplete/mapping.vim
@@ -41,6 +41,9 @@ function! deoplete#mapping#_restore_completeopt() abort
endif
endfunction
function! deoplete#mapping#_rpcrequest_wrapper(sources) abort
+ if !exists('g:deoplete#_initialized')
+ return ''
+ endif
call rpcnotify(g:deoplete#_channel_id,
\ 'deoplete_manual_completion_begin',
\ deoplete#init#_context('Manual', a:sources))
diff --git a/rplugin/python3/deoplete/__init__.py b/rplugin/python3/deoplete/__init__.py
index 4644b52..44f90c9 100644
--- a/rplugin/python3/deoplete/__init__.py
+++ b/rplugin/python3/deoplete/__init__.py
@@ -21,36 +21,21 @@ class DeopleteHandlers(object):
self._vim = vim
@neovim.function('_deoplete', sync=True)
- def init_python(self, args):
- self._deoplete = Deoplete(self._vim)
+ def init_channel(self, args):
self._vim.vars['deoplete#_channel_id'] = self._vim.channel_id
-
# Check neovim-python version.
try:
import pkg_resources
version = [pkg_resources.get_distribution('neovim').version]
except Exception:
- # Since neovim-client version 0.1.11
- if hasattr(neovim, 'VERSION'):
- version = ['{major}.{minor}.{patch}{prerelease}'.format(
- major=neovim.VERSION.major,
- minor=neovim.VERSION.minor,
- patch=neovim.VERSION.patch,
- prerelease=getattr(neovim.VERSION, 'prerelease', '')
- )]
- else:
- version = []
- python_dir = os.path.dirname(os.path.dirname(neovim.__file__))
- base = python_dir + '/neovim-*/'
- meta_files = glob(base + 'PKG-INFO') + glob(base + '/METADATA')
- for metadata in meta_files:
- with open(metadata, 'r', errors='replace') as f:
- for line in f:
- m = re.match('Version: (.+)', line)
- if m:
- version.append(m.group(1))
+ version = 'unknown'
self._vim.vars['deoplete#_neovim_python_version'] = version
+ @neovim.rpc_export('deoplete_init')
+ def init(self):
+ self._deoplete = Deoplete(self._vim)
+ self._vim.vars['deoplete#_initialized'] = 1
+
@neovim.rpc_export('deoplete_enable_logging')
def enable_logging(self, level, logfile):
logger.setup(self._vim, level, logfile)
diff --git a/rplugin/python3/deoplete/deoplete.py b/rplugin/python3/deoplete/deoplete.py
index 6055d81..f1fd9e4 100644
--- a/rplugin/python3/deoplete/deoplete.py
+++ b/rplugin/python3/deoplete/deoplete.py
@@ -39,6 +39,11 @@ class Deoplete(logger.LoggingMixin):
self._loaded_paths = set()
self._prev_results = {}
+ # on_init() call
+ context = self._vim.call('deoplete#init#_context', 'Init', [])
+ context['rpc'] = 'deoplete_on_event'
+ self.on_event(context)
+
def completion_begin(self, context):
self.check_recache(context)