mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-08 03:24:47 +08:00
Merge branch 'dev' of github.com:davidhalter/jedi-vim into dev
This commit is contained in:
@@ -68,7 +68,7 @@ if 1:
|
|||||||
text = 'import %s' % args.pop()
|
text = 'import %s' % args.pop()
|
||||||
scr = jedi.Script(text, 1, len(text), '')
|
scr = jedi.Script(text, 1, len(text), '')
|
||||||
try:
|
try:
|
||||||
path = scr.goto()[0].module_path
|
path = scr.goto_assignments()[0].module_path
|
||||||
except IndexError:
|
except IndexError:
|
||||||
path = None
|
path = None
|
||||||
if path and osp.isfile(path):
|
if path and osp.isfile(path):
|
||||||
@@ -92,7 +92,7 @@ if 1:
|
|||||||
else:
|
else:
|
||||||
text = 'import %s' % argl
|
text = 'import %s' % argl
|
||||||
script=jedi.Script(text, 1, len(text), '')
|
script=jedi.Script(text, 1, len(text), '')
|
||||||
comps = [ '%s%s' % (argl, c.complete) for c in script.complete()]
|
comps = ['%s%s' % (argl, c.complete) for c in script.completions()]
|
||||||
vim.command("let comps = '%s'" % '\n'.join(comps))
|
vim.command("let comps = '%s'" % '\n'.join(comps))
|
||||||
EOF
|
EOF
|
||||||
return comps
|
return comps
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ class PythonToVimStr(unicode):
|
|||||||
# support is pretty bad. don't ask how I came up with this... It just
|
# support is pretty bad. don't ask how I came up with this... It just
|
||||||
# works...
|
# works...
|
||||||
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
# It seems to be related to that bug: http://bugs.python.org/issue5876
|
||||||
s = self.encode('UTF-8')
|
if unicode is str:
|
||||||
|
s = self
|
||||||
|
else:
|
||||||
|
s = self.encode('UTF-8')
|
||||||
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"')
|
||||||
|
|
||||||
|
|
||||||
@@ -71,13 +74,14 @@ def complete():
|
|||||||
column += len(base)
|
column += len(base)
|
||||||
try:
|
try:
|
||||||
script = get_script(source=source, column=column)
|
script = get_script(source=source, column=column)
|
||||||
completions = script.complete()
|
completions = script.completions()
|
||||||
call_def = script.get_in_function_call()
|
sig = script.call_signatures()
|
||||||
|
call_def = sig[0] if sig else None
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
for c in completions:
|
for c in completions:
|
||||||
d = dict(word=PythonToVimStr(c.word[:len(base)] + c.complete),
|
d = dict(word=PythonToVimStr(c.name[:len(base)] + c.complete),
|
||||||
abbr=PythonToVimStr(c.word),
|
abbr=PythonToVimStr(c.name),
|
||||||
# stuff directly behind the completion
|
# stuff directly behind the completion
|
||||||
menu=PythonToVimStr(c.description),
|
menu=PythonToVimStr(c.description),
|
||||||
info=PythonToVimStr(c.doc), # docstr
|
info=PythonToVimStr(c.doc), # docstr
|
||||||
@@ -104,11 +108,11 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
|
|||||||
script = get_script()
|
script = get_script()
|
||||||
try:
|
try:
|
||||||
if is_related_name:
|
if is_related_name:
|
||||||
definitions = script.related_names()
|
definitions = script.usages()
|
||||||
elif is_definition:
|
elif is_definition:
|
||||||
definitions = script.get_definition()
|
definitions = script.goto_definitions()
|
||||||
else:
|
else:
|
||||||
definitions = script.goto()
|
definitions = script.goto_assignments()
|
||||||
except jedi.NotFoundError:
|
except jedi.NotFoundError:
|
||||||
echo_highlight(
|
echo_highlight(
|
||||||
"Cannot follow nothing. Put your cursor on a valid name.")
|
"Cannot follow nothing. Put your cursor on a valid name.")
|
||||||
@@ -159,7 +163,7 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
|
|||||||
def show_pydoc():
|
def show_pydoc():
|
||||||
script = get_script()
|
script = get_script()
|
||||||
try:
|
try:
|
||||||
definitions = script.get_definition()
|
definitions = script.goto_definitions()
|
||||||
except jedi.NotFoundError:
|
except jedi.NotFoundError:
|
||||||
definitions = []
|
definitions = []
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -199,7 +203,8 @@ def show_func_def(call_def=None, completion_lines=0):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if call_def == None:
|
if call_def == None:
|
||||||
call_def = get_script().get_in_function_call()
|
sig = get_script().call_signatures()
|
||||||
|
call_def = sig[0] if sig else None
|
||||||
clear_func_def()
|
clear_func_def()
|
||||||
|
|
||||||
if call_def is None:
|
if call_def is None:
|
||||||
@@ -232,7 +237,9 @@ def show_func_def(call_def=None, completion_lines=0):
|
|||||||
|
|
||||||
# Need to decode it with utf8, because vim returns always a python 2
|
# Need to decode it with utf8, because vim returns always a python 2
|
||||||
# string even if it is unicode.
|
# string even if it is unicode.
|
||||||
e = vim.eval('g:jedi#function_definition_escape').decode('UTF-8')
|
e = vim.eval('g:jedi#function_definition_escape')
|
||||||
|
if hasattr(e, 'decode'):
|
||||||
|
e = e.decode('UTF-8')
|
||||||
# replace line before with cursor
|
# replace line before with cursor
|
||||||
regex = "xjedi=%sx%sxjedix".replace('x', e)
|
regex = "xjedi=%sx%sxjedix".replace('x', e)
|
||||||
|
|
||||||
@@ -317,7 +324,7 @@ def tabnew(path):
|
|||||||
buf_nr = int(buf_nr) - 1
|
buf_nr = int(buf_nr) - 1
|
||||||
try:
|
try:
|
||||||
buf_path = vim.buffers[buf_nr].name
|
buf_path = vim.buffers[buf_nr].name
|
||||||
except IndexError:
|
except LookupError:
|
||||||
# Just do good old asking for forgiveness.
|
# Just do good old asking for forgiveness.
|
||||||
# don't know why this happens :-)
|
# don't know why this happens :-)
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user