mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
Unify Pyimport and goto
This commit is contained in:
@@ -376,6 +376,13 @@ def goto(mode="goto"):
|
||||
echo_highlight("Couldn't find any definitions for this.")
|
||||
elif len(names) == 1 and mode != "related_name":
|
||||
n = list(names)[0]
|
||||
_goto_specific_name(n)
|
||||
else:
|
||||
show_goto_multi_results(names, mode)
|
||||
return names
|
||||
|
||||
|
||||
def _goto_specific_name(n, options=''):
|
||||
if n.column is None:
|
||||
if n.is_keyword:
|
||||
echo_highlight("Cannot get the definition of Python keywords.")
|
||||
@@ -386,7 +393,7 @@ def goto(mode="goto"):
|
||||
using_tagstack = int(vim_eval('g:jedi#use_tag_stack')) == 1
|
||||
module_path = str(n.module_path)
|
||||
if (module_path or '') != vim.current.buffer.name:
|
||||
result = new_buffer(module_path,
|
||||
result = new_buffer(module_path, options=options,
|
||||
using_tagstack=using_tagstack)
|
||||
if not result:
|
||||
return []
|
||||
@@ -410,9 +417,6 @@ def goto(mode="goto"):
|
||||
vim.command('let &wildignore = %s' %
|
||||
repr(PythonToVimStr(old_wildignore)))
|
||||
vim.current.window.cursor = n.line, n.column
|
||||
else:
|
||||
show_goto_multi_results(names, mode)
|
||||
return names
|
||||
|
||||
|
||||
def relpath(path):
|
||||
@@ -1045,18 +1049,14 @@ def do_rename(replace, orig=None):
|
||||
@_check_jedi_availability(show_error=True)
|
||||
@catch_and_print_exceptions
|
||||
def py_import():
|
||||
# args are the same as for the :edit command
|
||||
args = shsplit(vim.eval('a:args'))
|
||||
import_path = args.pop()
|
||||
name = next(get_project().search(import_path), None)
|
||||
if name is None:
|
||||
echo_highlight('Cannot find %s in sys.path!' % import_path)
|
||||
else:
|
||||
if name.column is None: # Python modules always have a line number.
|
||||
echo_highlight('%s is a builtin module.' % import_path)
|
||||
echo_highlight('Cannot find %s in your project or on sys.path!' % import_path)
|
||||
else:
|
||||
cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
|
||||
new_buffer(str(name.module_path), cmd_args)
|
||||
_goto_specific_name(name, options=cmd_args)
|
||||
|
||||
|
||||
@catch_and_print_exceptions
|
||||
|
||||
Reference in New Issue
Block a user