|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | """
|
2 | 3 | The MIT License (MIT)
|
3 | 4 |
|
|
24 | 25 |
|
25 | 26 | import os
|
26 | 27 | import platform
|
| 28 | +import re |
27 | 29 | import sublime
|
28 | 30 | import sublime_plugin
|
29 | 31 |
|
30 |
| -from subprocess import Popen |
| 32 | +from subprocess import Popen, PIPE, STDOUT |
31 | 33 |
|
32 | 34 | SUMMIT_PLUGIN_PATH = os.path.split(os.path.abspath(__file__))[0]
|
33 | 35 | SUMMIT_SETTINGS = sublime.load_settings('SummitEditor.sublime-settings')
|
@@ -85,8 +87,28 @@ def simulate_with_args(self, sim_args):
|
85 | 87 |
|
86 | 88 | class SummitAutoBuildOnSave(sublime_plugin.EventListener):
|
87 | 89 | def on_post_save(self, view):
|
| 90 | + window = sublime.active_window() |
88 | 91 | is_summit_file = view.scope_name(0).startswith('source.lua.summit')
|
89 | 92 | auto_build = SUMMIT_SETTINGS.get('summit_simulate_on_save')
|
| 93 | + auto_lint = SUMMIT_SETTINGS.get('summit_lint_on_save') |
90 | 94 |
|
91 | 95 | if is_summit_file and auto_build:
|
92 |
| - sublime.active_window().run_command('build') |
| 96 | + window.run_command('build') |
| 97 | + |
| 98 | + if is_summit_file and auto_lint: |
| 99 | + output_panel = window.create_output_panel("mono") |
| 100 | + window.run_command("show_panel", {"panel": "output.mono"}) |
| 101 | + |
| 102 | + cmd = [ |
| 103 | + 'luacheck', |
| 104 | + view.file_name(), |
| 105 | + '--ignore', |
| 106 | + 'channel', |
| 107 | + 'util', |
| 108 | + '_S' |
| 109 | + ] |
| 110 | + proc = Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=1) |
| 111 | + output = '\n'.join([l.decode(encoding='UTF-8') for l in iter(proc.stdout.readline, b'')]) |
| 112 | + |
| 113 | + ansi_escape = re.compile(r'\x1b[^m]*m') |
| 114 | + output_panel.run_command("append", {"characters": ansi_escape.sub('', output)}) |
0 commit comments