def parse_region(rgn): if rgn is not None: start = parse_position(rgn.get('from')) end = parse_position(rgn.get('to')) if start is not None and end is not None: return symbols.Region(start, end) return None
def to_error(errmsg): filename, line, column, messy_details = errmsg.groups() line, column = int(line), int(column) column = ghc_column_to_sublime_column(view, line, column) line = line - 1 # Record the absolute, normalized path. return OutputMessage(os.path.normpath(os.path.join(base_dir, filename)), symbols.Region(symbols.Position(line, column)), messy_details.strip(), 'warning' if 'warning' in messy_details.lower() else 'error')
def to_error(errmsg): filename, line, column, messy_details = errmsg.groups() filename = os.path.normpath(os.path.join(base_dir, filename)) line, column = int(line), int(column) ## print('filename {0} line {1} column {2} messy_details {3}'.format(filename, line, column, messy_details)) column = ghc_column_to_sublime_column(view, line, column) line = line - 1 # Record the absolute, normalized path. return OutputMessage( view.window().find_open_file(filename), filename, Symbols.Region(Symbols.Position(line, column)), messy_details.strip(), 'warning' if 'warning' in messy_details.lower() else 'error')
def to_output_message(msg): filename = msg.get('source', {}).get('file', '<no file/command line/OPTIONS_GHC>') file_view = view.window().find_open_file(filename) if msg.get('region'): region = HsResultParse.parse_region( msg.get('region')).to_zero_based() else: region = Symbols.Region(0) level = msg.get('level', 'uncategorized') caption = level.capitalize() + ': ' + msg.get('note', {}).get( 'message', '') caption.replace('\n', '\n ') return OutputMessage(file_view, filename, region, caption, level)
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)