Skip to content

Commit 6279b37

Browse files
authored
Check if global state is already initialized before creating listeners (#562)
We were originally assuming that the global state was always going to be present when a listener is created. Due to the concurrent nature of the LSP, this is not always true. If the Rails + Tapioca add-on combination takes a while to finish booting, it's expected that the LSP may switch threads and a request will get executed before activating add-ons is complete. I started returning early if the global state is not yet available.
1 parent a1f3cc1 commit 6279b37

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def version
8181
).void
8282
end
8383
def create_code_lens_listener(response_builder, uri, dispatcher)
84-
CodeLens.new(@rails_runner_client, T.must(@global_state), response_builder, uri, dispatcher)
84+
return unless @global_state
85+
86+
CodeLens.new(@rails_runner_client, @global_state, response_builder, uri, dispatcher)
8587
end
8688

8789
sig do
@@ -92,7 +94,9 @@ def create_code_lens_listener(response_builder, uri, dispatcher)
9294
).void
9395
end
9496
def create_hover_listener(response_builder, node_context, dispatcher)
95-
Hover.new(@rails_runner_client, response_builder, node_context, T.must(@global_state), dispatcher)
97+
return unless @global_state
98+
99+
Hover.new(@rails_runner_client, response_builder, node_context, @global_state, dispatcher)
96100
end
97101

98102
sig do
@@ -116,8 +120,9 @@ def create_document_symbol_listener(response_builder, dispatcher)
116120
).void
117121
end
118122
def create_definition_listener(response_builder, uri, node_context, dispatcher)
119-
index = T.must(@global_state).index
120-
Definition.new(@rails_runner_client, response_builder, node_context, index, dispatcher)
123+
return unless @global_state
124+
125+
Definition.new(@rails_runner_client, response_builder, node_context, @global_state.index, dispatcher)
121126
end
122127

123128
sig do

0 commit comments

Comments
 (0)