diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 6850946..931584b 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -42,6 +42,15 @@ function! jedi#disable_debugging() Python jedi_vim.jedi.set_debug_function(None) endfunction +function! jedi#py_import(args) + Python jedi_vim.py_import() +endfun + +function! jedi#py_import_completions(argl, cmdl, pos) + Python jedi_vim.py_import_completions() +endfun + + " ------------------------------------------------------------------------ " show_documentation " ------------------------------------------------------------------------ @@ -83,53 +92,6 @@ function! jedi#show_documentation() let b:current_syntax = "rst" endfunction -" ------------------------------------------------------------------------ -" helper functions -" ------------------------------------------------------------------------ -function! jedi#py_import(args) -Python << EOF - # args are the same as for the :edit command -if 1: - import vim - import jedi - import os.path as osp - from shlex import split as shsplit - - args = shsplit(vim.eval('a:args')) - text = 'import %s' % args.pop() - scr = jedi.Script(text, 1, len(text), '') - try: - path = scr.goto_assignments()[0].module_path - except IndexError: - path = None - if path and osp.isfile(path): - cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) - jedi_vim.new_buffer(path, cmd_args) -EOF -endfun - -function! jedi#py_import_completion(argl, cmdl, pos) -Python << EOF -if 1: - import vim - import re - import json - argl = vim.eval('a:argl') - try: - import jedi - except ImportError as err: - print('Pyimport completion requires jedi module: https://github.com/davidhalter/jedi') - comps = [] - else: - text = 'import %s' % argl - script=jedi.Script(text, 1, len(text), '') - comps = ['%s%s' % (argl, c.complete) for c in script.completions()] - vim.command("let comps = '%s'" % '\n'.join(comps)) -EOF - return comps -endfun - - " ------------------------------------------------------------------------ " helper functions " ------------------------------------------------------------------------ diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 6452150..d5a25b2 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -83,6 +83,6 @@ endif " ------------------------------------------------------------------------ " PyImport command " ------------------------------------------------------------------------ -command! -nargs=1 -complete=custom,jedi#py_import_completion Pyimport :call jedi#py_import() +command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import() " vim: set et ts=4: diff --git a/plugin/jedi_vim.py b/plugin/jedi_vim.py index 2150700..aa74064 100644 --- a/plugin/jedi_vim.py +++ b/plugin/jedi_vim.py @@ -6,6 +6,7 @@ with VIM. import traceback # for exception output import re import os +from shlex import split as shsplit import vim import jedi @@ -310,6 +311,31 @@ def rename(): vim.current.window.cursor = cursor echo_highlight('Jedi did %s renames!' % len(temp_rename)) +def py_import(): + # args are the same as for the :edit command + args = shsplit(vim.eval('a:args')) + text = 'import %s' % args.pop() + scr = jedi.Script(text, 1, len(text), '') + try: + path = scr.goto_assignments()[0].module_path + except IndexError: + path = None + if path and os.path.isfile(path): + cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) + new_buffer(path, cmd_args) + +def py_import_completions(): + argl = vim.eval('a:argl') + try: + import jedi + except ImportError: + print('Pyimport completion requires jedi module: https://github.com/davidhalter/jedi') + comps = [] + else: + text = 'import %s' % argl + script=jedi.Script(text, 1, len(text), '') + comps = ['%s%s' % (argl, c.complete) for c in script.completions()] + vim.command("return '%s'" % '\n'.join(comps)) def new_buffer(path, options=''): path = repr(PythonToVimStr(path))