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,
26+ # 'has_inline': False,
2527# }
2628# `paths` is an OrderedDict to handle next/prev message.
2729# `path` is the absolute path to the file.
2830# `hidden` indicates that all messages have been dismissed.
31+ # `rendered` is the rustc-rendered output
32+ # 'has_inline' is a boolean indicating if inline messages were added
2933WINDOW_MESSAGES = {}
3034
3135
@@ -302,9 +306,8 @@ def _draw_region_highlights(view, batch):
302306
303307def batches_at_point (view , point , hover_zone ):
304308 """Return a list of message batches at the given point."""
305- try :
306- winfo = WINDOW_MESSAGES [view .window ().id ()]
307- except KeyError :
309+ winfo = get_window_info_for_view (view )
310+ if winfo is None :
308311 return
309312 if winfo ['hidden' ]:
310313 return
@@ -615,9 +618,8 @@ def redraw_all_open_views(window):
615618
616619def show_messages_for_view (view ):
617620 """Adds all phantoms and region outlines for a view."""
618- try :
619- winfo = WINDOW_MESSAGES [view .window ().id ()]
620- except KeyError :
621+ winfo = get_window_info_for_view (view )
622+ if winfo is None :
621623 return
622624 if winfo ['hidden' ]:
623625 return
@@ -628,9 +630,8 @@ def show_messages_for_view(view):
628630
629631
630632def draw_regions_if_missing (view ):
631- try :
632- winfo = WINDOW_MESSAGES [view .window ().id ()]
633- except KeyError :
633+ winfo = get_window_info_for_view (view )
634+ if winfo is None :
634635 return
635636 if winfo ['hidden' ]:
636637 return
@@ -1184,16 +1185,9 @@ def _save_batches(window, batches, msg_cb):
11841185 - Displays phantoms if a view is already open.
11851186 - Calls `msg_cb` for each individual message.
11861187 """
1187- wid = window .id ()
1188- try :
1189- path_to_batches = WINDOW_MESSAGES [wid ]['paths' ]
1190- except KeyError :
1191- path_to_batches = collections .OrderedDict ()
1192- WINDOW_MESSAGES [wid ] = {
1193- 'paths' : path_to_batches ,
1194- 'batch_index' : (- 1 , - 1 ),
1195- 'hidden' : False ,
1196- }
1188+ win_info = get_or_init_window_info (window )
1189+ win_info ['has_inline' ] = True
1190+ path_to_batches = win_info ['paths' ]
11971191
11981192 for batch in batches :
11991193 path_batches = path_to_batches .setdefault (batch .path (), [])
@@ -1202,7 +1196,7 @@ def _save_batches(window, batches, msg_cb):
12021196 path_batches .append (batch )
12031197 for i , msg in enumerate (batch ):
12041198 msg .region_key = 'rust-%i' % (num + i ,)
1205- if not WINDOW_MESSAGES [ wid ] ['hidden' ]:
1199+ if not win_info ['hidden' ]:
12061200 views = util .open_views_for_file (window , batch .path ())
12071201 if views :
12081202 # Phantoms seem to be attached to the buffer.
@@ -1212,3 +1206,32 @@ def _save_batches(window, batches, msg_cb):
12121206 if msg_cb :
12131207 for msg in batch :
12141208 msg_cb (msg )
1209+
1210+
1211+ def get_or_init_window_info (window ):
1212+ """Returns the window info for the given window, creating it if it hasn't been set."""
1213+ wid = window .id ()
1214+ try :
1215+ return WINDOW_MESSAGES [wid ]
1216+ except KeyError :
1217+ win_info = {
1218+ 'paths' : collections .OrderedDict (),
1219+ 'batch_index' : (- 1 , - 1 ),
1220+ 'hidden' : False ,
1221+ 'rendered' : '' ,
1222+ 'has_inline' : False ,
1223+ }
1224+ WINDOW_MESSAGES [wid ] = win_info
1225+ return win_info
1226+
1227+
1228+ def get_window_info_for_view (view ):
1229+ """Returns the window info for the given view, or None if not available."""
1230+ window = view .window ()
1231+ if window is None :
1232+ # I'm not entire sure why this happens sometimes.
1233+ return None
1234+ try :
1235+ return WINDOW_MESSAGES [window .id ()]
1236+ except KeyError :
1237+ return None
0 commit comments