Skip to content

Commit

Permalink
Add g:ncm2_jedi#settings, close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
roxma committed Jan 21, 2019
1 parent 47e0caf commit 0003b01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 5 additions & 2 deletions autoload/ncm2_jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

29 changes: 17 additions & 12 deletions pythonx/ncm2_jedi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import jedi
import os

from jedi import settings

logger = getLogger(__name__)

Expand All @@ -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']
Expand All @@ -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
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 0003b01

Please sign in to comment.