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 3f3ecb2

Browse files
committedSep 11, 2023
Add a command to view the rendered build results
1 parent 91a2f80 commit 3f3ecb2

File tree

5 files changed

+72
-17
lines changed

5 files changed

+72
-17
lines changed
 

‎RustEnhanced.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
"caption": "Rust: Open Debug Log",
5757
"command": "rust_open_log"
5858
},
59+
{
60+
"caption": "Rust: Open Last Build Output As View",
61+
"command": "rust_show_build_output"
62+
},
5963
{
6064
"caption": "Rust: Popup Message At Cursor",
6165
"command": "rust_message_popup"

‎SyntaxCheckPlugin.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class RustSyntaxCheckThread(rust_thread.RustThread, rust_proc.ProcListener):
6767
def __init__(self, view):
6868
self.view = view
6969
self.window = view.window()
70+
self.rendered = []
7071
super(RustSyntaxCheckThread, self).__init__(view.window())
7172

7273
def run(self):
@@ -190,23 +191,37 @@ def get_rustc_messages(self):
190191
#########################################################################
191192

192193
def on_begin(self, proc):
193-
pass
194+
self.rendered.append('[Running: %s]' % (' '.join(proc.cmd),))
194195

195196
def on_data(self, proc, data):
196197
log.log(self.window, data)
198+
self.rendered.append(data)
197199

198200
def on_error(self, proc, message):
199201
log.critical(self.window, 'Rust Error: %s', message)
202+
self.rendered.append(message)
200203

201204
def on_json(self, proc, obj):
202-
messages.add_rust_messages(self.window, self.msg_rel_path, obj,
205+
try:
206+
message = obj['message']
207+
except KeyError:
208+
return
209+
messages.add_rust_messages(self.window, self.msg_rel_path, message,
203210
self.current_target_src, msg_cb=None)
204211
if messages.has_message_for_path(self.window,
205212
self.triggered_file_name):
206213
self.this_view_found = True
214+
try:
215+
self.rendered.append(message['rendered'])
216+
except KeyError:
217+
pass
207218

208219
def on_finished(self, proc, rc):
209220
log.log(self.window, 'On-save check finished.')
221+
# TODO: Also put message in self.rendered about [Finished in …]
222+
# TODO: Figure out how to share all this code between here and opanel
223+
win_info = messages.get_or_init_window_info(self.window)
224+
win_info['rendered'] = ''.join(self.rendered)
210225

211226
def on_terminated(self, proc):
212227
log.log(self.window, 'Process Interrupted')

‎cargo_build.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,22 @@ def on_selection_modified_async(self):
521521
messages.update_status(view)
522522

523523

524+
class RustShowBuildOutput(sublime_plugin.WindowCommand):
525+
526+
"""Opens a view with the rustc-rendered compiler output."""
527+
528+
def run(self):
529+
view = self.window.new_file()
530+
view.set_scratch(True)
531+
view.set_name('Rust Enhanced Build Output')
532+
view.assign_syntax('Cargo.sublime-syntax')
533+
win_info = messages.get_or_init_window_info(self.window)
534+
output = win_info['rendered']
535+
if output == '':
536+
output = "No output available for this window."
537+
view.run_command('append', {'characters': output})
538+
539+
524540
class RustEventListener(sublime_plugin.EventListener):
525541

526542
def on_activated_async(self, view):

‎rust/messages.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
# Value is a dictionary: {
2222
# 'paths': {path: [MessageBatch, ...]},
2323
# 'batch_index': (path_idx, message_idx),
24-
# 'hidden': bool
24+
# 'hidden': bool,
25+
# 'rendered': string,
2526
# }
2627
# `paths` is an OrderedDict to handle next/prev message.
2728
# `path` is the absolute path to the file.
2829
# `hidden` indicates that all messages have been dismissed.
30+
# `rendered` is the rustc-rendered output
2931
WINDOW_MESSAGES = {}
3032

3133

@@ -1180,16 +1182,8 @@ def _save_batches(window, batches, msg_cb):
11801182
- Displays phantoms if a view is already open.
11811183
- Calls `msg_cb` for each individual message.
11821184
"""
1183-
wid = window.id()
1184-
try:
1185-
path_to_batches = WINDOW_MESSAGES[wid]['paths']
1186-
except KeyError:
1187-
path_to_batches = collections.OrderedDict()
1188-
WINDOW_MESSAGES[wid] = {
1189-
'paths': path_to_batches,
1190-
'batch_index': (-1, -1),
1191-
'hidden': False,
1192-
}
1185+
win_info = get_or_init_window_info(window)
1186+
path_to_batches = win_info['paths']
11931187

11941188
for batch in batches:
11951189
path_batches = path_to_batches.setdefault(batch.path(), [])
@@ -1198,7 +1192,7 @@ def _save_batches(window, batches, msg_cb):
11981192
path_batches.append(batch)
11991193
for i, msg in enumerate(batch):
12001194
msg.region_key = 'rust-%i' % (num + i,)
1201-
if not WINDOW_MESSAGES[wid]['hidden']:
1195+
if not win_info['hidden']:
12021196
views = util.open_views_for_file(window, batch.path())
12031197
if views:
12041198
# Phantoms seem to be attached to the buffer.
@@ -1208,3 +1202,18 @@ def _save_batches(window, batches, msg_cb):
12081202
if msg_cb:
12091203
for msg in batch:
12101204
msg_cb(msg)
1205+
1206+
1207+
def get_or_init_window_info(window):
1208+
wid = window.id()
1209+
try:
1210+
return WINDOW_MESSAGES[wid]
1211+
except KeyError:
1212+
win_info = {
1213+
'paths': collections.OrderedDict(),
1214+
'batch_index': (-1, -1),
1215+
'hidden': False,
1216+
'rendered': '',
1217+
}
1218+
WINDOW_MESSAGES[wid] = win_info
1219+
return win_info

‎rust/opanel.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(self, window, base_path, command_name, rustc_version):
7171
self.base_path = base_path
7272
self.command_name = command_name
7373
self.rustc_version = rustc_version
74+
self.rendered = []
7475

7576
def on_begin(self, proc):
7677
self.output_view = create_output_panel(self.window, self.base_path)
@@ -114,9 +115,16 @@ def on_error(self, proc, message):
114115
self._append(message)
115116

116117
def on_json(self, proc, obj):
117-
if 'message' in obj:
118-
messages.add_rust_messages(self.window, self.base_path, obj['message'],
119-
None, self.msg_cb)
118+
try:
119+
message = obj['message']
120+
except KeyError:
121+
return
122+
messages.add_rust_messages(self.window, self.base_path, message,
123+
None, self.msg_cb)
124+
try:
125+
self.rendered.append(message['rendered'])
126+
except KeyError:
127+
pass
120128

121129
def msg_cb(self, message):
122130
"""Display the message in the output panel. Also marks the message
@@ -155,6 +163,8 @@ def on_finished(self, proc, rc):
155163
# Tell Sublime to find all of the lines with pattern from
156164
# result_file_regex.
157165
self.output_view.find_all_results()
166+
win_info = messages.get_or_init_window_info(self.window)
167+
win_info['rendered'] = ''.join(self.rendered)
158168

159169
def on_terminated(self, proc):
160170
self._append('[Build interrupted]')
@@ -163,6 +173,7 @@ def _append(self, message, nl=True):
163173
if nl:
164174
message += '\n'
165175
_append(self.output_view, message)
176+
self.rendered.append(message)
166177

167178
def _display_debug(self, proc):
168179
# Display some information to help the user debug any build problems.

0 commit comments

Comments
 (0)
Please sign in to comment.