diff --git a/linter.py b/linter.py index 1ebad2f..67c722d 100644 --- a/linter.py +++ b/linter.py @@ -12,7 +12,9 @@ """This module exports the Annotations plugin class.""" import re -from SublimeLinter.lint import Linter, ERROR, WARNING + +import sublime +from SublimeLinter.lint import Linter, ERROR, WARNING, util def _escape_words(values): @@ -37,11 +39,6 @@ class Annotations(Linter): cmd = None line_col_base = (0, 0) - regex = ( - r'^(?P\d+):(?P\d+):' - r' (?P.+?) \((?P.+)\):' - r' (?P.*)' - ) # We use this to do the matching mark_regex_template = r'(?:(?P{infos})|(?P{warnings})|(?P{errors})):?\s*(?P.*)' @@ -54,7 +51,13 @@ class Annotations(Linter): 'infos': ['NOTE', 'README', 'INFO'], } - def run(self, cmd, code): + def lint(self, _code, _view_has_changed): + self.logger.info( + "%s: linting '%s'", + self.name, + util.canonical_filename(self.view), + ) + options = {} for option in ('errors', 'warnings', 'infos'): words = self.settings.get(option) @@ -63,7 +66,7 @@ def run(self, cmd, code): mark_regex = re.compile(self.mark_regex_template.format_map(options)) output = [] - regions = self.view.find_by_selector('comment - punctuation.definition.comment') + regions = self.view.find_by_selector(self.settings['comment_selector']) for region in regions: region_offset = self.view.rowcol(region.a) @@ -76,6 +79,7 @@ def run(self, cmd, code): row = region_offset[0] + i # Need to account for region column offset only in first row col = match.start() + (region_offset[1] if i == 0 else 0) + match_region = sublime.Region(region.a + match.start(), region.a + match.end()) message = match.group('message').strip() or '' word = match.group('error') if word: @@ -88,7 +92,19 @@ def run(self, cmd, code): word = match.group('info') error_type = 'info' - output.append('{row}:{col}: {error_type} ({word}): {message}' - .format(**locals())) - - return '\n'.join(output) + output.append(dict( + line=row, + start=col, + region=match_region, + # linter=, + error_type=error_type, + code=word, + msg=message, + filename=util.get_filename(self.view), + # uid=, + # priority=, + # panel_line=, + offending_text=word, + )) + + return output