File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -27,13 +27,18 @@ class Addon
27
27
28
28
@addons = T . let ( [ ] , T ::Array [ Addon ] )
29
29
@addon_classes = T . let ( [ ] , T ::Array [ T . class_of ( Addon ) ] )
30
+ # Addon instances that have declared a handler to accept file watcher events
31
+ @file_watcher_addons = T . let ( [ ] , T ::Array [ Addon ] )
30
32
31
33
class << self
32
34
extend T ::Sig
33
35
34
36
sig { returns ( T ::Array [ Addon ] ) }
35
37
attr_accessor :addons
36
38
39
+ sig { returns ( T ::Array [ Addon ] ) }
40
+ attr_accessor :file_watcher_addons
41
+
37
42
sig { returns ( T ::Array [ T . class_of ( Addon ) ] ) }
38
43
attr_reader :addon_classes
39
44
@@ -57,6 +62,7 @@ def load_addons(message_queue)
57
62
58
63
# Instantiate all discovered addon classes
59
64
self . addons = addon_classes . map ( &:new )
65
+ self . file_watcher_addons = addons . select { |addon | addon . respond_to? ( :workspace_did_change_watched_files ) }
60
66
61
67
# Activate each one of the discovered addons. If any problems occur in the addons, we don't want to
62
68
# fail to boot the server
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ def did_change_watched_files(changes)
229
229
end
230
230
end
231
231
232
+ Addon . file_watcher_addons . each { |addon | T . unsafe ( addon ) . workspace_did_change_watched_files ( changes ) }
232
233
VOID
233
234
end
234
235
Original file line number Diff line number Diff line change @@ -76,5 +76,24 @@ def name
76
76
Failed to activate
77
77
MESSAGE
78
78
end
79
+
80
+ def test_automatically_identifies_file_watcher_addons
81
+ klass = Class . new ( ::RubyLsp ::Addon ) do
82
+ def activate ( message_queue ) ; end
83
+ def deactivate ; end
84
+
85
+ def workspace_did_change_watched_files ( changes ) ; end
86
+ end
87
+
88
+ begin
89
+ queue = Thread ::Queue . new
90
+ Addon . load_addons ( queue )
91
+ assert_equal ( 1 , Addon . file_watcher_addons . length )
92
+ assert_instance_of ( klass , Addon . file_watcher_addons . first )
93
+ ensure
94
+ T . must ( queue ) . close
95
+ Addon . file_watcher_addons . clear
96
+ end
97
+ end
79
98
end
80
99
end
You can’t perform that action at this time.
0 commit comments