Skip to content

Commit

Permalink
Show first errors in output panel.
Browse files Browse the repository at this point in the history
Cache types for types commands ('show all types', 'expand to expression')
  • Loading branch information
mvoidex committed Sep 23, 2016
1 parent 56e2007 commit 6df68a7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
18 changes: 0 additions & 18 deletions autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@
EXPORT_MODULE_RE = re.compile(r'\bmodule\s+[\w\d\.]*$')


def is_scanned_source(view = None):
window, view, file_shown_in_view = get_haskell_command_window_view_file_project(view)
if file_shown_in_view is None:
return False
m = head_of(hsdev.client.module(file = file_shown_in_view))
return m is not None


def is_in_project(view = None):
window, view, file_shown_in_view = get_haskell_command_window_view_file_project(view)
if file_shown_in_view is None:
return False
m = head_of(hsdev.client.module(file = file_shown_in_view))
if m is None:
return False
return m.location.project is not None


# Gets available LANGUAGE options and import modules from ghc-mod
def get_language_pragmas():

Expand Down
18 changes: 18 additions & 0 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
symbol_file_regex = r'^Defined at: (.*):(\d+):(\d+)$'


def is_scanned_source(view = None):
window, view, file_shown_in_view = get_haskell_command_window_view_file_project(view)
if file_shown_in_view is None:
return False
m = head_of(hsdev.client.module(file = file_shown_in_view))
return m is not None


def is_in_project(view = None):
window, view, file_shown_in_view = get_haskell_command_window_view_file_project(view)
if file_shown_in_view is None:
return False
m = head_of(hsdev.client.module(file = file_shown_in_view))
if m is None:
return False
return m.location.project is not None


def show_declaration_info_panel(view, decl):
info = decl.detailed()
if get_setting_async('unicode_symbol_info'):
Expand Down
2 changes: 1 addition & 1 deletion hsdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ def wrapped(*args, **kwargs):
class HsDevAgent(threading.Thread):
sleep_timeout = 60.0 # agent sleeping timeout
min_ver = [0, 2, 0, 0] # minimal hsdev version
max_ver = [0, 2, 1, 0] # maximal hsdev version
max_ver = [0, 2, 2, 0] # maximal hsdev version

def __init__(self):
super(HsDevAgent, self).__init__()
Expand Down
8 changes: 6 additions & 2 deletions parseoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ def format_output_messages(messages):
summary['error'],
summary['warning'],
summary['hint'])
ordered = []
ordered.extend([m for m in messages if m.level == 'error'])
ordered.extend([m for m in messages if m.level == 'warning'])
ordered.extend([m for m in messages if m.level == 'hint'])
if PyV3:
details = '\n'.join(str(x) for x in messages)
details = '\n'.join(str(m) for m in ordered)
return '{0}\n\n{1}'.format(summary_line, details) if details else ''
else:
details = u'\n'.join(unicode(x) for x in messages)
details = u'\n'.join(unicode(m) for m in ordered)
return u'{0}\n\n{1}'.format(summary_line, details) if details else u''


Expand Down
24 changes: 17 additions & 7 deletions types.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,20 @@ def parse_type_output(view, s):
return result


def sorted_types(view, types, pt):
return sorted(
list(filter(lambda t: t.region(view).contains(pt), types)),
key = lambda t: t.region(view).size())


def get_type(view, filename, module_name, line, column, cabal = None):
result = None

if get_setting_async('enable_hsdev'):
# Convert from hsdev one-based locations to sublime zero-based positions
ts = get_types(filename, cabal = cabal)
pt = FilePosition(line, column).point(view)
types = sorted(
list(filter(lambda t: t.region(view).contains(pt), ts)),
key = lambda t: t.region(view).size())
return types
return sorted_types(view, ts, pt)
column = sublime_column_to_ghc_column(view, line, column)
line = line + 1
if get_setting_async('enable_hdevtools'):
Expand Down Expand Up @@ -209,10 +212,14 @@ def to_region_type(r):
to_file_pos(r['region']['to']))

def on_resp(rs):
on_result([to_region_type(r) for r in rs])
ts = [to_region_type(r) for r in rs]
file_types.set(filename, ts)
on_result(ts)
res = hsdev.client.types(files = [filename], ghc = get_ghc_opts(filename), wait = on_result is None, on_response = on_resp if on_result is not None else None)
if res is not None:
return [to_region_type(r) for r in res]
ts = [to_region_type(r) for r in res]
file_types.set(filename, ts)
return ts


class SublimeHaskellShowType(SublimeHaskellTextCommand):
Expand Down Expand Up @@ -403,7 +410,10 @@ class ExpandSelectionInfo(object):
def __init__(self, view, selection = None):
self.view = view
self.selection = selection if selection is not None else view.sel()[0]
types = get_type_view(view, self.selection)
if file_types.has(self.view.file_name()):
types = sorted_types(self.view, file_types.get(self.view.file_name()), self.selection.b)
else:
types = get_type_view(self.view, self.selection)
self.regions = [TypedRegion.fromRegionType(t, view) for t in types] if types else None
self.expanded_index = None

Expand Down

0 comments on commit 6df68a7

Please sign in to comment.