Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Automatic Type Popup] fix + remove type prefixes #34

Merged
merged 4 commits into from
Nov 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions text_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def run(self,edit):
def _handle_response(self,response):
type_spans = list(parse_exp_types(response))
if type_spans:
_type = next(filter_enclosing(self.view, self.view.sel()[0], type_spans), None)
if not _type is None:
type_span = next(filter_enclosing(self.view, self.view.sel()[0], type_spans), None)
if type_span is not None:
_type, span = type_span
self.view.show_popup(_type)


Expand Down
13 changes: 12 additions & 1 deletion utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ def within(smaller, larger):
return smaller.begin() >= larger.begin() and smaller.end() <= larger.end()

def filter_enclosing(view, region, span_pairs):
return (item for item, span in span_pairs if within(region, view_region_from_span(view, span)))
return ((item, span) for item, span in span_pairs if within(region, view_region_from_span(view, span)))

def shorten_module_prefixes(type_with_prefixes):
words = type_with_prefixes.replace("(", " ( ").replace("[", " [ ").split(' ')
return (" ".join(map(shorten_module_prefix, words)).replace(" ( ","(").replace(" [ ","["))

def shorten_module_prefix(prefixed_type):
words = prefixed_type.split('.')
if (len(words) > 1):
return ("_" + words[-1])
else:
return prefixed_type

def is_haskell_view(view):
return view.match_selector(view.sel()[0].begin(), "source.haskell")
Expand Down
31 changes: 15 additions & 16 deletions win.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sublime
except ImportError:
from test.stubs import sublime
from utility import first_folder, view_region_from_span
from utility import first_folder, view_region_from_span, filter_enclosing, shorten_module_prefixes
from response import parse_source_errors, parse_exp_types

class Win:
Expand Down Expand Up @@ -40,21 +40,22 @@ def highlight_type(self, exp_types):
most specific one for now, but it gives us the types all the way out to the topmost
expression.
"""
types = list(parse_exp_types(exp_types))
if types:
# Display the first type in a region and in the status bar
type_spans = list(parse_exp_types(exp_types))
if type_spans:
view = self.window.active_view()
(type, span) = types[0]
if span:
if Win.show_popup:
view.show_popup(type)
view.set_status("type_at_cursor", type)
type_span = next(filter_enclosing(view, view.sel()[0], type_spans), None)
if type_span is not None:
(_type, span) = type_span
view.set_status("type_at_cursor", _type)
view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED)
else:
# Clear type-at-cursor display
for view in self.window.views():
view.set_status("type_at_cursor", "")
view.add_regions("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED)
if Win.show_popup:
view.show_popup(shorten_module_prefixes(_type))
return

# Clear type-at-cursor display
for view in self.window.views():
view.set_status("type_at_cursor", "")
view.add_regions("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED)


def handle_source_errors(self, source_errors):
Expand Down Expand Up @@ -136,5 +137,3 @@ def highlight_errors(self, errors):
for view in self.window.views():
view.add_regions("errors", error_regions_by_view_id.get(view.id(), []), "invalid", "dot", sublime.DRAW_OUTLINED)
view.add_regions("warnings", warning_regions_by_view_id.get(view.id(), []), "comment", "dot", sublime.DRAW_OUTLINED)