def on_autofix(self, corrections): output_messages = [ ParseOutput.OutputMessage( m['source']['file'], HsResultParse.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] ParseOutput.set_global_error_messages(output_messages) output_text = ParseOutput.format_output_messages(output_messages) if Settings.PLUGIN.show_error_window: sublime.set_timeout(lambda: ParseOutput.write_output(self.view, output_text, Common.get_cabal_project_dir_of_file(self.filename) or \ os.path.dirname(self.filename), panel_display=not self.fly_mode and len(output_messages)), 0) sublime.set_timeout( lambda: ParseOutput.mark_messages_in_views(output_messages), 0)
def on_autofix(self, corrections): # Oh, this looks pretty ugly. But, list comprehensions are supposedly faster than loops. And since this is # is supporting Haskell, why not use the functional approach? :-) output_messages = [ParseOutput.OutputMessage(msg.get('source', {}).get('file', '<no file/command line/OPTIONS_GHC>'), HsResultParse.parse_region(msg.get('region')).to_zero_based() \ if msg.get('region') is not None else Symbols.Region(0), msg.get('level', 'uncategorized').capitalize() + ': ' + \ msg.get('note', {}).get('message', '').replace('\n', '\n '), msg.get('level', 'uncategorized')) for msg in self.msgs] # Hack alert: Region and Position.to_zero_based() return the original object (self) after updating it. 'and' returns the # right hand side, which is never None or a false value. self.corrections_dict = dict( ((os.path.normpath(c.file), c.message_region.start.line, c.message_region.start.column), c) for c in [ corr.message_region.to_zero_based() and corr for corr in corrections or [] ]) 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] ParseOutput.set_global_error_messages(output_messages) output_text = ParseOutput.format_output_messages(output_messages) if Settings.PLUGIN.show_error_window: cabal_proj_dir = Common.get_cabal_project_dir_of_file( self.filename) or os.path.dirname(self.filename) panel_display = not self.fly_mode and output_messages sublime.set_timeout( lambda: ParseOutput.write_output( self.view, output_text, cabal_proj_dir, panel_display), 0) sublime.set_timeout( lambda: ParseOutput.mark_messages_in_views(output_messages), 0)