|
1 | 1 | import json |
2 | 2 | import subprocess |
3 | 3 | import sys |
| 4 | +import re |
4 | 5 |
|
5 | 6 | import sublime_plugin |
6 | 7 | import sublime |
@@ -29,7 +30,8 @@ def run(self, edit): |
29 | 30 | window = self.view.window() |
30 | 31 |
|
31 | 32 | settings = sublime.load_settings('Crystal.sublime-settings') |
32 | | - command = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"] |
| 33 | + #command = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"] |
| 34 | + command = [settings.get("crystal_cmd"), "tool", "format", "-", "--no-color"] |
33 | 35 |
|
34 | 36 | popen_args = dict(args=command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
35 | 37 | # Prevent flashing terminal windows |
@@ -59,13 +61,32 @@ def run(self, edit): |
59 | 61 | window.run_command("hide_panel") |
60 | 62 |
|
61 | 63 | else: |
62 | | - error = json.loads(stderr) |
63 | | - error_pos = self.view.text_point(error[0]["line"] - 1, error[0]["column"] - 1) |
64 | | - line_region = self.view.full_line(error_pos) |
65 | | - self.view.add_regions('crystal_errors', [line_region], 'comment', 'dot', sublime.HIDDEN) |
| 64 | + error_pos = None |
| 65 | + pattern = r"Error: Syntax error in .+?:(\d+): (.+)" |
| 66 | + match = re.match(pattern, stderr) |
| 67 | + if match: |
| 68 | + error_pos = int(match.group(1)) |
| 69 | + error = match.group(2) |
| 70 | + else: |
| 71 | + error_pos = None |
| 72 | + error = stderr |
| 73 | + # error = json.loads(stderr) |
| 74 | + # error_pos = self.view.text_point(error[0]["line"] - 1, error[0]["column"] - 1) |
| 75 | + |
| 76 | + if error_pos: |
| 77 | + line_region = self.view.full_line(error_pos) |
| 78 | + self.view.add_regions('crystal_errors', [line_region], 'comment', 'dot', sublime.HIDDEN) |
66 | 79 |
|
67 | 80 | error_panel = window.create_output_panel('crystal_errors') |
68 | | - error_panel.run_command("append", {"characters": |
69 | | - "Error at line %d, column %d: %s" % (error[0]["line"], error[0]["column"], error[0]['message']) |
70 | | - }) |
| 81 | + # error_panel.run_command("append", {"characters": |
| 82 | + # "Error at line %d, column %d: %s" % (error[0]["line"], error[0]["column"], error[0]['message']) |
| 83 | + # }) |
| 84 | + |
| 85 | + if error_pos: |
| 86 | + error_panel.run_command("append", {"characters": |
| 87 | + "Error at line %d: %s" % (error_pos, error) |
| 88 | + }) |
| 89 | + else: |
| 90 | + error_panel.run_command("append", {"characters": error}) |
| 91 | + |
71 | 92 | window.run_command("show_panel", {"panel": "output.crystal_errors"}) |
0 commit comments