18
18
module RubyLsp
19
19
module Tapioca
20
20
class Addon < ::RubyLsp ::Addon
21
- extend T ::Sig
22
-
23
21
#: -> void
24
22
def initialize
25
23
super
@@ -44,7 +42,7 @@ def activate(global_state, outgoing_queue)
44
42
# Get a handle to the Rails add-on's runtime client. The call to `rails_runner_client` will block this thread
45
43
# until the server has finished booting, but it will not block the main LSP. This has to happen inside of a
46
44
# thread
47
- addon = T . cast ( ::RubyLsp ::Addon . get ( "Ruby LSP Rails" , ">= 0.4.0" , "< 0.5" ) , :: RubyLsp ::Rails ::Addon )
45
+ addon = ::RubyLsp ::Addon . get ( "Ruby LSP Rails" , ">= 0.4.0" , "< 0.5" ) #: as :: RubyLsp::Rails::Addon
48
46
@rails_runner_client = addon . rails_runner_client
49
47
@outgoing_queue << Notification . window_log_message ( "Activating Tapioca add-on v#{ version } " )
50
48
@rails_runner_client . register_server_addon ( File . expand_path ( "server_addon.rb" , __dir__ ) )
@@ -93,10 +91,11 @@ def workspace_did_change_watched_files(changes)
93
91
has_route_change = false #: bool
94
92
has_fixtures_change = false #: bool
95
93
needs_compiler_reload = false #: bool
94
+ index = @index #: as !nil
96
95
97
96
constants = changes . flat_map do |change |
98
- path = URI ( change [ :uri ] ) . to_standardized_path
99
- next unless file_updated? ( change , path )
97
+ path = URI ( change [ :uri ] ) . to_standardized_path #: String?
98
+ next unless path && file_updated? ( change , path )
100
99
101
100
if File . fnmatch ( "**/fixtures/**/*.yml{,.erb}" , path , File ::FNM_PATHNAME | File ::FNM_EXTGLOB )
102
101
has_fixtures_change = true
@@ -115,7 +114,7 @@ def workspace_did_change_watched_files(changes)
115
114
next
116
115
end
117
116
118
- entries = T . must ( @ index) . entries_for ( change [ :uri ] )
117
+ entries = index . entries_for ( change [ :uri ] )
119
118
next unless entries
120
119
121
120
entries . filter_map do |entry |
@@ -178,14 +177,16 @@ def send_usage_telemetry(feature_name)
178
177
179
178
#: (Hash[Symbol, untyped] change, String path) -> bool
180
179
def file_updated? ( change , path )
180
+ queue = @outgoing_queue #: as !nil
181
+
181
182
case change [ :type ]
182
183
when Constant ::FileChangeType ::CREATED
183
184
@file_checksums [ path ] = Zlib . crc32 ( File . read ( path ) ) . to_s
184
185
return true
185
186
when Constant ::FileChangeType ::CHANGED
186
187
current_checksum = Zlib . crc32 ( File . read ( path ) ) . to_s
187
188
if @file_checksums [ path ] == current_checksum
188
- T . must ( @outgoing_queue ) << Notification . window_log_message (
189
+ queue << Notification . window_log_message (
189
190
"File has not changed. Skipping #{ path } " ,
190
191
type : Constant ::MessageType ::INFO ,
191
192
)
@@ -196,7 +197,7 @@ def file_updated?(change, path)
196
197
when Constant ::FileChangeType ::DELETED
197
198
@file_checksums . delete ( path )
198
199
else
199
- T . must ( @outgoing_queue ) << Notification . window_log_message (
200
+ queue << Notification . window_log_message (
200
201
"Unexpected file change type: #{ change [ :type ] } " ,
201
202
type : Constant ::MessageType ::WARNING ,
202
203
)
@@ -207,16 +208,16 @@ def file_updated?(change, path)
207
208
208
209
#: -> void
209
210
def run_gem_rbi_check
210
- gem_rbi_check = RunGemRbiCheck . new ( T . must ( @global_state ) . workspace_path )
211
+ state = @global_state #: as !nil
212
+ gem_rbi_check = RunGemRbiCheck . new ( state . workspace_path )
211
213
gem_rbi_check . run
212
214
213
- T . must ( @outgoing_queue ) << Notification . window_log_message (
214
- gem_rbi_check . stdout ,
215
- ) unless gem_rbi_check . stdout . empty?
216
- T . must ( @outgoing_queue ) << Notification . window_log_message (
217
- gem_rbi_check . stderr ,
218
- type : Constant ::MessageType ::WARNING ,
219
- ) unless gem_rbi_check . stderr . empty?
215
+ queue = @outgoing_queue #: as !nil
216
+ queue << Notification . window_log_message ( gem_rbi_check . stdout ) unless gem_rbi_check . stdout . empty?
217
+
218
+ unless gem_rbi_check . stderr . empty?
219
+ queue << Notification . window_log_message ( gem_rbi_check . stderr , type : Constant ::MessageType ::WARNING )
220
+ end
220
221
end
221
222
end
222
223
end
0 commit comments