Skip to content

Commit

Permalink
Properly display build errors on ST3 <r3153
Browse files Browse the repository at this point in the history
As of r3153, Sublime Text's built-in ExecCommand sends strings to on_data, and
as a string must be sent to on_finished with the formatted build output. If
we're on an older version of Sublime Text, therefore, we need to keep track of
whether we have received strings or bytes and send the right data format to
on_finished.
  • Loading branch information
sentience committed Mar 30, 2018
1 parent e9ef161 commit 36314c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion elm_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ElmMakeCommand(default_exec.ExecCommand):
# inspired by: http://www.sublimetext.com/forum/viewtopic.php?t=12028
def run(self, error_format, info_format, syntax, null_device, warnings, **kwargs):
self.buffer = ''
self.data_in_bytes = False # ST3 r3153 changed ExecCommand from bytes to str so we must detect which we get and handle appropriately: https://github.com/elm-community/SublimeElmLanguageSupport/issues/48
self.warnings = warnings == "true"
self.error_format = string.Template(error_format)
self.info_format = string.Template(info_format)
Expand Down Expand Up @@ -50,17 +51,20 @@ def style_output(self, syntax):
self.debug_text = get_string('make.missing_plugin')

def on_data(self, proc, data):
# ST3 ExecCommand base class changed from receiving bytes to str
if isinstance(data, str):
self.buffer += data
else:
# ST3 r3153 changed ExecCommand from bytes to str so we must detect which we get and handle appropriately: https://github.com/elm-community/SublimeElmLanguageSupport/issues/48
self.data_in_bytes = True
self.buffer += data.decode(self.encoding)

def on_finished(self, proc):
result_strs = self.buffer.split('\n')
flat_map = lambda f, xss: sum(map(f, xss), [])
output_strs = flat_map(self.format_result, result_strs) + ['']
output_data = '\n'.join(output_strs)
# ST3 r3153 changed ExecCommand from bytes to str so we must detect which we get and handle appropriately: https://github.com/elm-community/SublimeElmLanguageSupport/issues/48
output_data = output_data.encode(self.encoding) if self.data_in_bytes else output_data
super(ElmMakeCommand, self).on_data(proc, output_data)
super(ElmMakeCommand, self).on_finished(proc)

Expand Down
3 changes: 3 additions & 0 deletions messages/0.22.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New in Elm Language Support 0.22.3 (Mar 30, 2018)

- Fix: Properly display build errors on Sublime Text 3 releases prior to r3153.

0 comments on commit 36314c6

Please sign in to comment.