Skip to content

Commit

Permalink
vim: compute enclosing types lazily as is done in emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
trefis committed Jun 29, 2017
1 parent a25eefe commit 1733043
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion vim/merlin/autoload/merlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,13 @@ def vim_type_enclosing():
vim_type_reset()
try:
to_line, to_col = vim.current.window.cursor
enclosing_types = command2(["type-enclosing", "-position", fmtpos((to_line,to_col))], track_verbosity=True)
enclosing_types = command2(
["type-enclosing",
"-position", fmtpos((to_line,to_col)),
"-index", "0"
],
track_verbosity=True
)
if enclosing_types != []:
return vim_next_enclosing()
else:
Expand Down Expand Up @@ -639,11 +645,25 @@ def enclosing_tail_info(record):
if record['tail'] == 'position': return ' (* tail position *)'
return ''

def enclosing_type_text(record):
if isinstance(record['type'], int):
types = command2(
["type-enclosing",
"-position", fmtpos(record['start']),
"-index", str(record['type'])
],
track_verbosity=True
)
return types[record['type']]['type']
else:
return record['type']

def vim_current_enclosing():
global enclosing_types
global current_enclosing
tmp = enclosing_types[current_enclosing]
tmp['matcher'] = make_matcher(tmp['start'], tmp['end'])
tmp['type'] = enclosing_type_text(tmp)
tmp['tail_info'] = enclosing_tail_info(tmp)
return json.dumps(tmp)

Expand Down

0 comments on commit 1733043

Please sign in to comment.