From 413cb8335435b75a0e1bde1b68453a1cd0e96e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vion?= Date: Mon, 2 Nov 2015 15:31:55 +0100 Subject: [PATCH 1/4] [Automatic Type Popup] fix + remove type prefixes --- utility.py | 7 +++++++ win.py | 23 ++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/utility.py b/utility.py index e5a5078..38073e5 100644 --- a/utility.py +++ b/utility.py @@ -72,6 +72,13 @@ def within(smaller, larger): def filter_enclosing(view, region, span_pairs): return (item for item, span in span_pairs if within(region, view_region_from_span(view, span))) +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") diff --git a/win.py b/win.py index 7ef193c..6800708 100644 --- a/win.py +++ b/win.py @@ -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_prefix from response import parse_source_errors, parse_exp_types class Win: @@ -40,21 +40,14 @@ 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 - view = self.window.active_view() - (type, span) = types[0] - if span: + type_spans = list(parse_exp_types(exp_types)) + if type_spans: + _view = self.window.active_view() + _type = next(filter_enclosing(_view, _view.sel()[0], type_spans), None) + if not _type is None: + _view.set_status("type_at_cursor", _type) if Win.show_popup: - view.show_popup(type) - 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) + _view.show_popup(shorten_module_prefix(_type)) def handle_source_errors(self, source_errors): From d7ab889d5b54dc6603d9b64bfdbf0b6c7cf73474 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Wed, 4 Nov 2015 21:35:32 +0100 Subject: [PATCH 2/4] make sure type in status is cleared, disable checks on regions --- test/test_listeners.py | 2 +- test/test_win.py | 2 +- win.py | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/test/test_listeners.py b/test/test_listeners.py index d95b77e..5448a8d 100644 --- a/test/test_listeners.py +++ b/test/test_listeners.py @@ -58,7 +58,7 @@ def test_type_at_cursor_tests(self): listener.on_selection_modified(view) view.set_status.assert_called_with("type_at_cursor", type_info) - view.add_regions.assert_called_with("type_at_cursor", ANY, "storage.type", "", sublime.DRAW_OUTLINED) + #view.add_regions.assert_called_with("type_at_cursor", ANY, "storage.type", "", sublime.DRAW_OUTLINED) def test_request_completions(self): diff --git a/test/test_win.py b/test/test_win.py index b35d2bf..2caa191 100644 --- a/test/test_win.py +++ b/test/test_win.py @@ -30,7 +30,7 @@ def test_highlight_type_clear(self): Win(window).highlight_type([]) view.set_status.assert_called_with("type_at_cursor", "") - view.add_regions.assert_called_with("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED) + #view.add_regions.assert_called_with("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED) def test_highlight_no_errors(self): diff --git a/win.py b/win.py index 6800708..7839e2e 100644 --- a/win.py +++ b/win.py @@ -42,12 +42,19 @@ def highlight_type(self, exp_types): """ type_spans = list(parse_exp_types(exp_types)) if type_spans: - _view = self.window.active_view() - _type = next(filter_enclosing(_view, _view.sel()[0], type_spans), None) + view = self.window.active_view() + _type = next(filter_enclosing(view, view.sel()[0], type_spans), None) if not _type is None: - _view.set_status("type_at_cursor", _type) + view.set_status("type_at_cursor", _type) + #view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED) if Win.show_popup: - _view.show_popup(shorten_module_prefix(_type)) + view.show_popup(shorten_module_prefix(_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): From 8d7be70c246d30bde1238c5cb143b972a0766c85 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Wed, 4 Nov 2015 21:56:07 +0100 Subject: [PATCH 3/4] also restore regions being auto-highlighted --- test/test_listeners.py | 2 +- test/test_win.py | 2 +- text_commands.py | 5 +++-- utility.py | 2 +- win.py | 9 +++++---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/test_listeners.py b/test/test_listeners.py index 5448a8d..d95b77e 100644 --- a/test/test_listeners.py +++ b/test/test_listeners.py @@ -58,7 +58,7 @@ def test_type_at_cursor_tests(self): listener.on_selection_modified(view) view.set_status.assert_called_with("type_at_cursor", type_info) - #view.add_regions.assert_called_with("type_at_cursor", ANY, "storage.type", "", sublime.DRAW_OUTLINED) + view.add_regions.assert_called_with("type_at_cursor", ANY, "storage.type", "", sublime.DRAW_OUTLINED) def test_request_completions(self): diff --git a/test/test_win.py b/test/test_win.py index 2caa191..b35d2bf 100644 --- a/test/test_win.py +++ b/test/test_win.py @@ -30,7 +30,7 @@ def test_highlight_type_clear(self): Win(window).highlight_type([]) view.set_status.assert_called_with("type_at_cursor", "") - #view.add_regions.assert_called_with("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED) + view.add_regions.assert_called_with("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED) def test_highlight_no_errors(self): diff --git a/text_commands.py b/text_commands.py index 9f45ad4..2a05b0d 100644 --- a/text_commands.py +++ b/text_commands.py @@ -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) diff --git a/utility.py b/utility.py index 38073e5..7db91ca 100644 --- a/utility.py +++ b/utility.py @@ -70,7 +70,7 @@ 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_prefix(prefixed_type): words = prefixed_type.split('.') diff --git a/win.py b/win.py index 7839e2e..acaaf55 100644 --- a/win.py +++ b/win.py @@ -43,10 +43,11 @@ def highlight_type(self, exp_types): type_spans = list(parse_exp_types(exp_types)) if type_spans: view = self.window.active_view() - _type = next(filter_enclosing(view, view.sel()[0], type_spans), None) - if not _type is None: + 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) + view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED) if Win.show_popup: view.show_popup(shorten_module_prefix(_type)) return @@ -54,7 +55,7 @@ def highlight_type(self, exp_types): # 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) + view.add_regions("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED) def handle_source_errors(self, source_errors): From 69de0fa83580218c77374c34261fcd31688e9e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vion?= Date: Sun, 15 Nov 2015 10:34:06 +0100 Subject: [PATCH 4/4] fix type prefix shortening --- utility.py | 4 ++++ win.py | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/utility.py b/utility.py index 7db91ca..5ffc040 100644 --- a/utility.py +++ b/utility.py @@ -72,6 +72,10 @@ def within(smaller, larger): def filter_enclosing(view, region, span_pairs): 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): diff --git a/win.py b/win.py index acaaf55..bdf6dc2 100644 --- a/win.py +++ b/win.py @@ -5,7 +5,7 @@ import sublime except ImportError: from test.stubs import sublime -from utility import first_folder, view_region_from_span, filter_enclosing, shorten_module_prefix +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: @@ -49,7 +49,7 @@ def highlight_type(self, exp_types): view.set_status("type_at_cursor", _type) view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED) if Win.show_popup: - view.show_popup(shorten_module_prefix(_type)) + view.show_popup(shorten_module_prefixes(_type)) return # Clear type-at-cursor display @@ -137,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) - -