From 168769c95b3a0f02e6060a9ed1accb00015c4524 Mon Sep 17 00:00:00 2001 From: camila <47485054+camila314@users.noreply.github.com> Date: Thu, 6 Mar 2025 23:45:46 -0600 Subject: [PATCH 1/3] Update linter.py --- linter.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/linter.py b/linter.py index d7c1ab7..9f43ce0 100644 --- a/linter.py +++ b/linter.py @@ -22,6 +22,7 @@ logger = logging.getLogger("SublimeLinter.plugin.sublime-syntax") +carats = re.compile(r'\^+\s*') class SublimeSyntax(Linter): @@ -37,15 +38,36 @@ class SublimeSyntax(Linter): cmd = None # We implement a custom `run` method regex = ( - r'^[^:]+:(?P\d+):((?P\d+):)? ' - r'(?P.+)' + r'^.+?:\d+:(?P\d+)\n' + r'(?P.+)\n' + r'\d+ \| .+\n' + r'(?P\d+) \| (?P.+)\n' ) + multiline = True # An empty selector matches all views defaults = { 'selector': '' } word_re = r'.' # only highlight a single character + def reposition_match(self, line, col, m, virtual_view): + err_pos = 0 + err_len = len(m.message) + msg = "" + if "<-" in m.message: + err_pos = m.message.index("<-") + 2 + msg = m.message.split("<-")[1] + else: + car = carats.search(m.message) + if car: + err_pos = car.end() + msg = m.message[car.end():] + else: + return super().reposition_match(line, col, m, virtual_view) + + m.message = msg + return (line, err_pos, err_len) + @classmethod def can_lint_view(cls, view, settings): """Check if file is 'lintable'.""" @@ -85,6 +107,7 @@ def run(self, cmd, code): start_time = time.time() while time.time() <= start_time + 1: try: + #raise OSError sublime.load_binary_resource(resource_path) except OSError: logger.debug("ST couldn't find our temporary file; re-polling…") @@ -94,12 +117,12 @@ def run(self, cmd, code): else: logger.warning("Waiting for ST to find our temporary file '%r' timed out", resource_path) - assertions, test_output_lines = sublime_api.run_syntax_test(resource_path) logger.debug('assertions: {}'.format(assertions)) output = "\n".join(test_output_lines) - if "unable to read file" in output: + logger.debug("\n" + output) + if "unable to read file2" in output: logger.error(output) return output @@ -186,4 +209,4 @@ def _temporary_resource_file(text, prefix='', suffix=''): try: os.rmdir(_temp_path) except OSError as e: - logger.debug("unable to delete temporary folder; %s", e) + logger.warning("unable to delete temporary folder; %s", e) From a88c6ed26dca782bdca737aa190ec0e4b90c8f7d Mon Sep 17 00:00:00 2001 From: camila <47485054+camila314@users.noreply.github.com> Date: Thu, 6 Mar 2025 23:47:38 -0600 Subject: [PATCH 2/3] Update linter.py --- linter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/linter.py b/linter.py index 9f43ce0..444c7eb 100644 --- a/linter.py +++ b/linter.py @@ -107,7 +107,6 @@ def run(self, cmd, code): start_time = time.time() while time.time() <= start_time + 1: try: - #raise OSError sublime.load_binary_resource(resource_path) except OSError: logger.debug("ST couldn't find our temporary file; re-polling…") @@ -117,12 +116,12 @@ def run(self, cmd, code): else: logger.warning("Waiting for ST to find our temporary file '%r' timed out", resource_path) + assertions, test_output_lines = sublime_api.run_syntax_test(resource_path) logger.debug('assertions: {}'.format(assertions)) output = "\n".join(test_output_lines) - logger.debug("\n" + output) - if "unable to read file2" in output: + if "unable to read file" in output: logger.error(output) return output @@ -209,4 +208,4 @@ def _temporary_resource_file(text, prefix='', suffix=''): try: os.rmdir(_temp_path) except OSError as e: - logger.warning("unable to delete temporary folder; %s", e) + logger.debug("unable to delete temporary folder; %s", e) From bdd5d1880f73fcacd09ea5e01f78bbe898eb4f52 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Thu, 12 Jun 2025 21:43:28 +0200 Subject: [PATCH 3/3] Revise `regex` and `reposition_match` --- linter.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/linter.py b/linter.py index 444c7eb..d5eb7ee 100644 --- a/linter.py +++ b/linter.py @@ -22,7 +22,6 @@ logger = logging.getLogger("SublimeLinter.plugin.sublime-syntax") -carats = re.compile(r'\^+\s*') class SublimeSyntax(Linter): @@ -39,33 +38,23 @@ class SublimeSyntax(Linter): cmd = None # We implement a custom `run` method regex = ( r'^.+?:\d+:(?P\d+)\n' - r'(?P.+)\n' + # `message` includes everything until we find two line breaks + r'(?P.+?): (?P.+\n' r'\d+ \| .+\n' - r'(?P\d+) \| (?P.+)\n' + # Capturing `line_text` and `markers` here makes repositioning easier + r'(?P\d+) \| (?P(?P.*(<-|\^+|@+)\s*).+)\n' + r'[\S\s]*?' + r')\n\n' ) multiline = True # An empty selector matches all views defaults = { 'selector': '' } - word_re = r'.' # only highlight a single character def reposition_match(self, line, col, m, virtual_view): - err_pos = 0 - err_len = len(m.message) - msg = "" - if "<-" in m.message: - err_pos = m.message.index("<-") + 2 - msg = m.message.split("<-")[1] - else: - car = carats.search(m.message) - if car: - err_pos = car.end() - msg = m.message[car.end():] - else: - return super().reposition_match(line, col, m, virtual_view) - - m.message = msg + err_pos = len(m.markers) + err_len = len(m.line_text) return (line, err_pos, err_len) @classmethod @@ -120,7 +109,8 @@ def run(self, cmd, code): assertions, test_output_lines = sublime_api.run_syntax_test(resource_path) logger.debug('assertions: {}'.format(assertions)) - output = "\n".join(test_output_lines) + # Ensure each error is terminated by two line breaks + output = "\n".join(test_output_lines) + "\n" if "unable to read file" in output: logger.error(output)