Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. diff --git a/Packages/Merlin/sublime-text-merlin.py b/Packages/Merlin/sublime-text-merlin.py
  2. --- a/Packages/Merlin/sublime-text-merlin.py
  3. +++ b/Packages/Merlin/sublime-text-merlin.py
  4. @@ -248,6 +248,57 @@
  5. else:
  6. opened_view.run_command("insert_code", { "arg": sig })
  7.  
  8. +class MerlinInfoPopup:
  9. + """
  10. + Pop up a menu at a point describing an expression
  11. + """
  12. +
  13. + def __init__(self, view, point):
  14. + merlin = merlin_view(view)
  15. + merlin.sync()
  16. +
  17. + line, col = view.rowcol(point)
  18. +
  19. + # FIXME: proper integration into sublime-text
  20. + # enclosing is a list of json objects of the form:
  21. + # { 'type': string;
  22. + # 'tail': "no"|"position"|"call" // tailcall information
  23. + # 'start', 'end': {'line': int, 'col': int}
  24. + # }
  25. + self.enclosing = merlin.type_enclosing(line + 1, col)
  26. + self.declaration = merlin.locate(line + 1, col, kind="mli")
  27. + self.definition = merlin.locate(line + 1, col, kind="ml")
  28. + self.view = view
  29. + self.point = point
  30. +
  31. + def _type_str(self):
  32. + if len(self.enclosing) > 0:
  33. + return clean_whitespace(self.enclosing[0]['type'])
  34. + else:
  35. + return ""
  36. +
  37. + def _loc_link(self, loc):
  38. + if isinstance(loc, dict):
  39. + pos = loc['pos']
  40. + if 'file' in loc:
  41. + short_file = os.path.basename(loc['file'])
  42. + filename = "%s:%d:%d" % (loc.get('file',''), pos['line'], pos['col'] + 1)
  43. + return "<a href=\"{}\">{}:{}</a>".format(filename, short_file,pos['line'])
  44. + else:
  45. + return "[this file]:" + pos['line']
  46. + else:
  47. + return ""+loc
  48. +
  49. + def show_popup(self):
  50. + print('showing popup')
  51. + content = "<b>Definition:</b> {} <br><b>Declaration:</b> {}<br><b>Type:</b><br> {}".format(self._loc_link(self.definition),self._loc_link(self.declaration), self._type_str())
  52. + self.view.show_popup(content,
  53. + sublime.HIDE_ON_MOUSE_MOVE_AWAY, self.point,
  54. + 600,150, self.on_navigate)
  55. +
  56. + def on_navigate(self, href):
  57. + self.view.window().open_file(href, sublime.ENCODED_POSITION)
  58. +
  59. class InsertCodeCommand(sublime_plugin.TextCommand):
  60. def run(self, edit, arg):
  61. self.view.insert(edit, self.view.size(), arg)
  62. @@ -735,6 +786,11 @@
  63. view.erase_regions('ocaml-underlines-errors')
  64. #merlin_error_panel.close()
  65.  
  66. + @only_ocaml
  67. + def on_hover(self, view, point, hover_zone):
  68. + if hover_zone == sublime.HOVER_TEXT:
  69. + popup = MerlinInfoPopup(view, point)
  70. + popup.show_popup()
  71.  
  72. def _plugin_dir(self):
  73. path = os.path.realpath(__file__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement