diff --git a/README.md b/README.md index 14328c6..08cb911 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,10 @@ of your virtualenv. Read [jedi-environments](https://jedi.readthedocs.io/en/latest/docs/api.html#environments) for more information. + +### `g:ncm2_jedi#settings` + +Defaults to `{}`. + +Read [jedi-settings](https://jedi.readthedocs.io/en/latest/docs/settings.html) +for more information. diff --git a/autoload/ncm2_jedi.vim b/autoload/ncm2_jedi.vim index 8e72611..005cb4c 100644 --- a/autoload/ncm2_jedi.vim +++ b/autoload/ncm2_jedi.vim @@ -11,6 +11,10 @@ let g:ncm2_jedi#environment = get(g:, \ 'ncm2_jedi#environment', \ '') +let g:ncm2_jedi#settings = get(g:, + \ 'ncm2_jedi#settings', + \ {}) + if g:ncm2_jedi#python_version != 2 let g:ncm2_jedi#proc = yarp#py3('ncm2_jedi') else @@ -48,7 +52,6 @@ func! ncm2_jedi#on_warmup(ctx) endfunc func! ncm2_jedi#on_complete(ctx) - let env = get(b:, 'ncm2_jedi_environment', g:ncm2_jedi#environment) - call g:ncm2_jedi#proc.try_notify('on_complete', a:ctx, getline(1, '$'), env) + call g:ncm2_jedi#proc.try_notify('on_complete', a:ctx, getline(1, '$')) endfunc diff --git a/pythonx/ncm2_jedi.py b/pythonx/ncm2_jedi.py index 4c2c0e7..c99f927 100644 --- a/pythonx/ncm2_jedi.py +++ b/pythonx/ncm2_jedi.py @@ -6,7 +6,7 @@ import re import jedi import os - +from jedi import settings logger = getLogger(__name__) @@ -18,16 +18,21 @@ class Source(Ncm2Source): def __init__(self, vim): Ncm2Source.__init__(self, vim) - self._envs = {} - def get_env(self, env): + env = vim.vars['ncm2_jedi#environment'] if not env: - return jedi.get_default_environment() - if env not in self._envs: - self._envs[env] = jedi.create_environment(env) - return self._envs[env] + self._env = jedi.get_default_environment() + else: + self._env = jedi.create_environment(env) + + rc_settings = vim.vars['ncm2_jedi#settings'] + for name in rc_settings: + setattr(settings, name, rc_settings[name]) - def on_complete(self, ctx, lines, env): + def get_env(self): + return self._env + + def on_complete(self, ctx, lines): path = ctx['filepath'] typed = ctx['typed'] lnum = ctx['lnum'] @@ -48,7 +53,7 @@ def on_complete(self, ctx, lines, env): logger.info('context [%s]', ctx) - env = self.get_env(env) + env = self.get_env() script = jedi.Script(src, lnum, len(typed), path, environment=env) is_import = False @@ -89,18 +94,18 @@ def on_complete(self, ctx, lines, env): insert = complete.complete - item = dict(word=ctx['base']+insert, + item = dict(word=ctx['base'] + insert, icase=1, dup=1, menu=complete.description, info=complete.docstring()) - item = self.match_formalize(ctx, item) - # Fix the user typed case if item['word'].lower() == complete.name.lower(): item['word'] = complete.name + item = self.match_formalize(ctx, item) + # snippet support try: if (complete.type == 'function' or complete.type == 'class'):