@@ -222,32 +222,22 @@ def run(self):
222
222
ON_LOAD_MESSAGES_ENABLED = True
223
223
224
224
225
- class CargoEventListener (sublime_plugin .EventListener ):
225
+ class MessagesViewEventListener (sublime_plugin .ViewEventListener ):
226
226
227
227
"""Every time a new file is loaded, check if is a Rust file with messages,
228
228
and if so, display the messages.
229
229
"""
230
230
231
- def on_load (self , view ):
232
- if ON_LOAD_MESSAGES_ENABLED and util .active_view_is_rust (view = view ):
233
- # For some reason, view.window() returns None here.
234
- # Use set_timeout to give it time to attach to a window.
235
- sublime .set_timeout (
236
- lambda : messages .show_messages_for_view (view ), 1 )
231
+ @classmethod
232
+ def is_applicable (cls , settings ):
233
+ return ON_LOAD_MESSAGES_ENABLED and util .is_rust_view (settings )
237
234
238
- def on_query_context (self , view , key , operator , operand , match_all ):
239
- # Used by the Escape-key keybinding to dismiss inline phantoms.
240
- if key == 'rust_has_messages' :
241
- try :
242
- winfo = messages .WINDOW_MESSAGES [view .window ().id ()]
243
- has_messages = not winfo ['hidden' ]
244
- except KeyError :
245
- has_messages = False
246
- if operator == sublime .OP_EQUAL :
247
- return operand == has_messages
248
- elif operator == sublime .OP_NOT_EQUAL :
249
- return operand != has_messages
250
- return None
235
+ @classmethod
236
+ def applies_to_primary_view_only (cls ):
237
+ return False
238
+
239
+ def on_load_async (self ):
240
+ messages .show_messages_for_view (self .view )
251
241
252
242
253
243
class NextPrevBase (sublime_plugin .WindowCommand ):
@@ -486,15 +476,79 @@ class CargoMessageHover(sublime_plugin.ViewEventListener):
486
476
487
477
@classmethod
488
478
def is_applicable (cls , settings ):
489
- s = settings .get ('syntax' )
490
- package_name = __package__ .split ('.' )[0 ]
491
- return s == 'Packages/%s/RustEnhanced.sublime-syntax' % (package_name ,)
479
+ return util .is_rust_view (settings )
480
+
481
+ @classmethod
482
+ def applies_to_primary_view_only (cls ):
483
+ return False
492
484
493
485
def on_hover (self , point , hover_zone ):
494
486
if util .get_setting ('rust_phantom_style' , 'normal' ) == 'popup' :
495
487
messages .message_popup (self .view , point , hover_zone )
496
488
497
489
490
+ class RustMessagePopupCommand (sublime_plugin .TextCommand ):
491
+
492
+ """Manually display a popup for any message under the cursor."""
493
+
494
+ def run (self , edit ):
495
+ for r in self .view .sel ():
496
+ messages .message_popup (self .view , r .begin (), sublime .HOVER_TEXT )
497
+
498
+
499
+ class RustMessageStatus (sublime_plugin .ViewEventListener ):
500
+
501
+ """Display message under cursor in status bar."""
502
+
503
+ @classmethod
504
+ def is_applicable (cls , settings ):
505
+ return (util .is_rust_view (settings )
506
+ and util .get_setting ('rust_message_status_bar' , False ))
507
+
508
+ @classmethod
509
+ def applies_to_primary_view_only (cls ):
510
+ return False
511
+
512
+ def on_selection_modified_async (self ):
513
+ # https://github.com/SublimeTextIssues/Core/issues/289
514
+ # Only works with the primary view, get the correct view.
515
+ # (Also called for each view, unfortunately.)
516
+ active_view = self .view .window ().active_view ()
517
+ if active_view and active_view .buffer_id () == self .view .buffer_id ():
518
+ view = active_view
519
+ else :
520
+ view = self .view
521
+ messages .update_status (view )
522
+
523
+
524
+ class RustEventListener (sublime_plugin .EventListener ):
525
+
526
+ def on_activated_async (self , view ):
527
+ # This is a workaround for this bug:
528
+ # https://github.com/SublimeTextIssues/Core/issues/2411
529
+ # It would be preferable to use ViewEventListener, but it doesn't work
530
+ # on duplicate views created with Goto Anything.
531
+ if not util .active_view_is_rust (view = view ):
532
+ return
533
+ if util .get_setting ('rust_message_status_bar' , False ):
534
+ messages .update_status (view )
535
+ messages .draw_regions_if_missing (view )
536
+
537
+ def on_query_context (self , view , key , operator , operand , match_all ):
538
+ # Used by the Escape-key keybinding to dismiss inline phantoms.
539
+ if key == 'rust_has_messages' :
540
+ try :
541
+ winfo = messages .WINDOW_MESSAGES [view .window ().id ()]
542
+ has_messages = not winfo ['hidden' ]
543
+ except KeyError :
544
+ has_messages = False
545
+ if operator == sublime .OP_EQUAL :
546
+ return operand == has_messages
547
+ elif operator == sublime .OP_NOT_EQUAL :
548
+ return operand != has_messages
549
+ return None
550
+
551
+
498
552
class RustAcceptSuggestedReplacement (sublime_plugin .TextCommand ):
499
553
500
554
"""Used for suggested replacements issued by the compiler to apply the
0 commit comments