Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d0d1987

Browse files
committedMar 29, 2017
Stop looking for JSON output during Cargo build once compile is finished.
This fixes issues with "cargo run" if your program outputs { at the start of a line.
1 parent 2f263c3 commit d0d1987

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎rust/rust_proc.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import json
77
import os
8+
import re
89
import signal
910
import subprocess
1011
import sys
@@ -266,6 +267,7 @@ def wait(self):
266267
return rc
267268

268269
def _read_stdout(self):
270+
decode_json = True
269271
while True:
270272
line = self.proc.stdout.readline()
271273
if not line:
@@ -276,21 +278,25 @@ def _read_stdout(self):
276278
line = line.decode('utf-8')
277279
except:
278280
self.listener.on_error(self,
279-
'Error decoding UTF-8: %r' % line)
281+
'[Error decoding UTF-8: %r]' % line)
280282
continue
281-
if line.startswith('{'):
283+
if decode_json and line.startswith('{'):
282284
try:
283285
result = json.loads(line)
284286
except:
285287
self.listener.on_error(self,
286-
'Error loading JSON from rust:\n%r' % line)
288+
'[Error loading JSON from rust: %r]' % line)
287289
else:
288290
try:
289291
self.listener.on_json(self, result)
290292
except:
291293
self._cleanup()
292294
raise
293295
else:
296+
if re.match('^\s*Finished', line):
297+
# If using "cargo run", we don't want to capture lines
298+
# starting with open bracket.
299+
decode_json = False
294300
# Sublime always uses \n internally.
295301
line = line.replace('\r\n', '\n')
296302
self.listener.on_data(self, line)

0 commit comments

Comments
 (0)