show_call_signatures shows now all call signatures if there are multiple, and not just one.

This commit is contained in:
David Halter
2013-08-22 17:18:25 +04:30
parent 59be959a3d
commit 0b8448804d

View File

@@ -98,8 +98,7 @@ def completions():
completions = [] completions = []
signatures = [] signatures = []
#print 'end', strout show_call_signatures(signatures)
show_call_signatures(signatures, len(completions))
vim.command('return ' + strout) vim.command('return ' + strout)
@@ -200,36 +199,39 @@ def clear_call_signatures():
def show_call_signatures(signatures=()): def show_call_signatures(signatures=()):
if vim.eval("has('conceal') && g:jedi#show_call_signatures") == '0': if vim.eval("has('conceal') && g:jedi#show_call_signatures") == '0':
return return
try: try:
if signatures == None: if signatures == ():
sig = get_script().call_signatures() signatures = get_script().call_signatures()
call_def = sig[0] if sig else None
clear_call_signatures() clear_call_signatures()
if call_def is None: if not signatures:
return return
row, column = call_def.bracket_start for i, signature in enumerate(signatures):
if column < 1 or row == 0: line, column = signature.bracket_start
return # edge cases, just ignore # signatures are listed above each other
line_to_replace = line - i - 1
# because there's a space before the bracket
insert_column = column - 1
if insert_column < 0 or line_to_replace <= 0:
# Edge cases, when the call signature has no space on the screen.
break
# TODO check if completion menu is above or below # TODO check if completion menu is above or below
row_to_replace = row - 1 line = vim.eval("getline(%s)" % line_to_replace)
line = vim.eval("getline(%s)" % row_to_replace)
insert_column = column - 1 # because there's a space before the bracket params = [p.get_code().replace('\n', '') for p in signature.params]
params = [p.get_code().replace('\n', '') for p in call_def.params]
try: try:
params[call_def.index] = '*%s*' % params[call_def.index] params[signature.index] = '*%s*' % params[signature.index]
except (IndexError, TypeError): except (IndexError, TypeError):
pass pass
# This stuff is reaaaaally a hack! I cannot stress enough, that this is # This stuff is reaaaaally a hack! I cannot stress enough, that
# a stupid solution. But there is really no other yet. There is no # this is a stupid solution. But there is really no other yet.
# possibility in VIM to draw on the screen, but there will be one (see # There is no possibility in VIM to draw on the screen, but there
# :help todo Patch to access screen under Python. (Marko Mahni, 2010 # will be one (see :help todo Patch to access screen under Python.
# Jul 18)) # (Marko Mahni, 2010 Jul 18))
text = " (%s) " % ', '.join(params) text = " (%s) " % ', '.join(params)
text = ' ' * (insert_column - len(line)) + text text = ' ' * (insert_column - len(line)) + text
end_column = insert_column + len(text) - 2 # -2 due to bold symbols end_column = insert_column + len(text) - 2 # -2 due to bold symbols
@@ -258,7 +260,7 @@ def show_call_signatures(signatures=()):
tup = '%s, %s' % (len(add), replace) tup = '%s, %s' % (len(add), replace)
repl = prefix + (regex % (tup, text)) + add + line[end_column:] repl = prefix + (regex % (tup, text)) + add + line[end_column:]
vim.eval('setline(%s, %s)' % (row_to_replace, repr(PythonToVimStr(repl)))) vim.eval('setline(%s, %s)' % (line_to_replace, repr(PythonToVimStr(repl))))
except Exception: except Exception:
print(traceback.format_exc()) print(traceback.format_exc())