Skip to content
This repository

Show warnings when they are selected with the cursor #4

Open
wants to merge 4 commits into from

3 participants

Niklas Hambüchen Alexandr Ruchkin Yghor Kerscher
Niklas Hambüchen
Owner

Originally, we showed all warnings and errors in the error panel.

That was a bit obtrusive, so since a3f6363, only errors are shown there.

With this commit, warning details are shown when the cursor is in the corresponding line.

Niklas Hambüchen
Owner
nh2 commented January 12, 2013

Update: This doesn't work properly yet, as there doesn't seem to be a way to close a specific panel - this would simply close all panels, e.g. search, which is bad.

Niklas Hambüchen
Owner
nh2 commented January 14, 2013

As of 97b57c9 we at least have warnings showing up in general again.

Alexandr Ruchkin
Owner

Is this pull request still actual?

Niklas Hambüchen
Owner
nh2 commented March 28, 2013

No, it has never worked perfectly - it's a work in progress with a problem I haven't found a workaround for yet. See the comment a bit further up about it closing all panels (also search) - I don't know how to only close one (our) panel.

Yghor Kerscher

Maybe the solution proposed down the comments at #134 could work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 58 additions and 0 deletions. Show diff stats Hide diff stats

  1. 58  autobuild.py
58  autobuild.py
@@ -11,6 +11,11 @@
11 11
 
12 12
 ERROR_PANEL_NAME = 'haskell_error_checker'
13 13
 
  14
+# Global mappings { view_id -> { lineno -> error } }, lineno is 0-indexed
  15
+# (inspired by SublimeLinter)
  16
+ERRORS = {}
  17
+WARNINGS = {}
  18
+
14 19
 # This regex matches an unindented line, followed by zero or more
15 20
 # indented, non-empty lines.
16 21
 # The first line is divided into a filename, a line number, and a column.
@@ -21,7 +26,21 @@
21 26
 # Extract the filename, line, column, and description from an error message:
22 27
 result_file_regex = r'^(\S*?): line (\d+), column (\d+):$'
23 28
 
  29
+
  30
+# From SublineLinter
  31
+def last_selected_lineno(view):
  32
+    viewSel = view.sel()
  33
+    if not viewSel:
  34
+        return None
  35
+    return view.rowcol(viewSel[0].end())[0]
  36
+
  37
+
24 38
 class SublimeHaskellAutobuild(sublime_plugin.EventListener):
  39
+
  40
+    def __init__(self):
  41
+        super(SublimeHaskellAutobuild, self).__init__()
  42
+        self.last_selected_lineno = None
  43
+
25 44
     def on_post_save(self, view):
26 45
         # If the edited file was Haskell code within a cabal project, try to
27 46
         # compile it.
@@ -34,6 +53,29 @@ def on_post_save(self, view):
34 53
                 args=(view, cabal_project_dir))
35 54
             thread.start()
36 55
 
  56
+    def on_selection_modified(self, view):
  57
+        cabal_project_dir = get_cabal_project_dir_of_view(view)
  58
+
  59
+        this_view_has_a_warning = view.id() in WARNINGS
  60
+
  61
+        if cabal_project_dir is not None and this_view_has_a_warning:
  62
+            lineno = last_selected_lineno(view)
  63
+            if lineno != self.last_selected_lineno:
  64
+                self.last_selected_lineno = lineno
  65
+
  66
+                vid = view.id()
  67
+
  68
+                # Only deal with warnings if there are no errors
  69
+                if not ERRORS.get(vid):
  70
+                    # We would like to close the panel here when moving away from a warning region,
  71
+                    #     hide_output(view)
  72
+                    # but does not seem to work as it closes *the active panel* (e.g. also find).
  73
+                    # So the user has to close it manually with ESC for now.
  74
+                    warning = WARNINGS.get(vid, {}).get(lineno)
  75
+                    if warning:
  76
+                        write_output(view, unicode(warning), cabal_project_dir)
  77
+
  78
+
37 79
 class ErrorMessage(object):
38 80
     "Describe an error or warning message produced by GHC."
39 81
     def __init__(self, filename, line, column, message):
@@ -124,6 +166,14 @@ def mark_errors_in_this_view(errors, view):
124 166
     # Add all error and warning regions in this view.
125 167
     error_regions = []
126 168
     warning_regions = []
  169
+
  170
+    # Update global error/warning dicts
  171
+    # TODO this is redundant with the other error lists
  172
+    vid = view.id()
  173
+    # ERRORS, WARNINGS store lines 0-indexed
  174
+    ERRORS[vid] = dict( (e.line - 1, e) for e in errors if not e.is_warning )
  175
+    WARNINGS[vid] = dict( (e.line - 1, e) for e in errors if e.is_warning )
  176
+
127 177
     for e in errors:
128 178
         region = e.find_region_in_view(view)
129 179
         if (e.is_warning):
@@ -162,8 +212,16 @@ def write_output(view, text, cabal_project_dir):
162 212
     output_view.set_read_only(True)
163 213
     # Show the results panel:
164 214
     view.window().run_command('show_panel', {'panel': 'output.' + ERROR_PANEL_NAME})
  215
+    print "  show view", view
  216
+    # view.window().run_command('show_panel', {'panel': 'output.gaga'})
165 217
 
166 218
 def hide_output(view):
  219
+    # TODO The 'panel' key doesn't appear in the API; most probably, it is ignored,
  220
+    #      and simply the current panel is hidden.
  221
+    # In theory, this should work:
  222
+    #     run_command('show_panel', {'panel': 'output.' + ERROR_PANEL_NAME, 'toggle': True})
  223
+    # but 'toggle' doesn't seem to work on output panels (it works on the 'console' panel).
  224
+    # There doesn't currently seem to be a way to close a panel by name.
167 225
     view.window().run_command('hide_panel', {'panel': 'output.' + ERROR_PANEL_NAME})
168 226
 
169 227
 def parse_error_messages(base_dir, text):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.