Factor out annotate_description

This uses d.type, but special-cases functions and statements.
This commit is contained in:
Daniel Hahler
2018-07-15 18:22:51 +02:00
committed by Dave Halter
parent 8e077adb2f
commit 66b6a20041

View File

@@ -348,6 +348,19 @@ def relpath(path):
return path return path
def annotate_description(d):
code = d.get_line_code().strip()
if d.type == 'statement':
return code
if d.type == 'function':
if code.startswith('def'):
return code
typ = 'def'
else:
typ = d.type
return '[%s] %s' % (typ, code)
def show_goto_multi_results(definitions): def show_goto_multi_results(definitions):
"""Create a quickfix list for multiple definitions.""" """Create a quickfix list for multiple definitions."""
lst = [] lst = []
@@ -359,9 +372,8 @@ def show_goto_multi_results(definitions):
# well. # well.
lst.append(dict(text=PythonToVimStr(d.description))) lst.append(dict(text=PythonToVimStr(d.description)))
else: else:
text = '[%s] %s' % (d.description, d.get_line_code().strip()) text = annotate_description(d)
filename = relpath(d.module_path) lst.append(dict(filename=PythonToVimStr(relpath(d.module_path)),
lst.append(dict(filename=PythonToVimStr(filename),
lnum=d.line, col=d.column + 1, lnum=d.line, col=d.column + 1,
text=PythonToVimStr(text))) text=PythonToVimStr(text)))
vim_eval('setqflist(%s)' % repr(lst)) vim_eval('setqflist(%s)' % repr(lst))