def on_autofix(self, corrections): output_messages = [OutputMessage( m['source']['file'], hsdev.parse_region(m['region']).to_zero_based(), m['level'].capitalize() + ': ' + m['note']['message'].replace('\n', '\n '), m['level']) for m in self.messages] self.corrections = corrections for corr in self.corrections: corr.message_region.to_zero_based() self.corrections_dict = dict(((os.path.normpath(c.file), c.message_region.start.line, c.message_region.start.column), c) for c in self.corrections) for omsg in output_messages: okey = (os.path.normpath(omsg.filename), omsg.region.start.line, omsg.region.start.column) if okey in self.corrections_dict: omsg.correction = self.corrections_dict[okey] set_global_error_messages(output_messages) output_text = format_output_messages(output_messages) if get_setting_async('show_error_window'): sublime.set_timeout(lambda: write_output( self.view, output_text, get_cabal_project_dir_of_file(self.filename) or os.path.dirname(self.filename), show_panel = not self.fly_mode and len(output_messages)), 0) sublime.set_timeout(lambda: mark_messages_in_views(output_messages), 0)
def go_chain(self, cmds): try: if not cmds: self.status_msg.stop() output_messages = [ OutputMessage( m['source']['file'], OutputPoint( int(m['region']['from']['line']) - 1, int(m['region']['from']['column']) - 1), OutputPoint( int(m['region']['to']['line']) - 1, int(m['region']['to']['column']) - 1), m['level'].capitalize() + ': ' + m['note']['message'].replace('\n', '\n '), m['level']) for m in self.messages ] set_global_error_messages(output_messages) output_text = format_output_messages(output_messages) if output_text: if get_setting_async('show_error_window'): sublime.set_timeout( lambda: write_output( self.view, output_text, get_cabal_project_dir_of_file(self.filename) or os.path.dirname(self.filename), show_panel=not self.fly_mode), 0) sublime.set_timeout( lambda: mark_messages_in_views(output_messages), 0) # autocomplete.hsdev_client.autofix_show(self.msgs, on_response = self.on_autofix) else: cmd, tail_cmds = cmds[0], cmds[1:] (fn, modify_args, modify_msgs, kwargs) = cmd def on_resp(msgs): self.messages.extend(modify_msgs(msgs)) self.msgs.extend(msgs) self.go_chain(tail_cmds) def on_err(err): self.status_msg.fail() self.go_chain([]) fn(modify_args(self.filename), contents=self.contents, wait=False, on_response=on_resp, on_error=on_err, **kwargs) except Exception as e: log('hsdev ghc-mod chain fails with: {0}'.format(e), log_error) self.status_msg.stop()
def go_chain(self, cmds): try: if not cmds: self.status_msg.stop() output_messages = [OutputMessage( m['source']['file'], OutputPoint( int(m['region']['from']['line']) - 1, int(m['region']['from']['column']) - 1), OutputPoint( int(m['region']['to']['line']) - 1, int(m['region']['to']['column']) - 1), m['level'].capitalize() + ': ' + m['note']['message'].replace('\n', '\n '), m['level']) for m in self.messages] set_global_error_messages(output_messages) output_text = format_output_messages(output_messages) if output_text: if get_setting_async('show_error_window'): sublime.set_timeout(lambda: write_output( self.view, output_text, get_cabal_project_dir_of_file(self.filename) or os.path.dirname(self.filename), show_panel = not self.fly_mode), 0) sublime.set_timeout(lambda: mark_messages_in_views(output_messages), 0) # autocomplete.hsdev_client.autofix_show(self.msgs, on_response = self.on_autofix) else: cmd, tail_cmds = cmds[0], cmds[1:] (fn, modify_args, modify_msgs, kwargs) = cmd def on_resp(msgs): self.messages.extend(modify_msgs(msgs)) self.msgs.extend(msgs) self.go_chain(tail_cmds) def on_err(err): self.status_msg.fail() self.go_chain([]) fn(modify_args(self.filename), contents = self.contents, wait = False, on_response = on_resp, on_error = on_err, **kwargs) except Exception as e: log('hsdev ghc-mod chain fails with: {0}'.format(e), log_error) self.status_msg.stop()