Skip to content

Commit

Permalink
Check if global state is already initialized before creating listeners (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
vinistock authored Jan 28, 2025
1 parent a1f3cc1 commit 6279b37
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ruby_lsp/ruby_lsp_rails/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def version
).void
end
def create_code_lens_listener(response_builder, uri, dispatcher)
CodeLens.new(@rails_runner_client, T.must(@global_state), response_builder, uri, dispatcher)
return unless @global_state

CodeLens.new(@rails_runner_client, @global_state, response_builder, uri, dispatcher)
end

sig do
Expand All @@ -92,7 +94,9 @@ def create_code_lens_listener(response_builder, uri, dispatcher)
).void
end
def create_hover_listener(response_builder, node_context, dispatcher)
Hover.new(@rails_runner_client, response_builder, node_context, T.must(@global_state), dispatcher)
return unless @global_state

Hover.new(@rails_runner_client, response_builder, node_context, @global_state, dispatcher)
end

sig do
Expand All @@ -116,8 +120,9 @@ def create_document_symbol_listener(response_builder, dispatcher)
).void
end
def create_definition_listener(response_builder, uri, node_context, dispatcher)
index = T.must(@global_state).index
Definition.new(@rails_runner_client, response_builder, node_context, index, dispatcher)
return unless @global_state

Definition.new(@rails_runner_client, response_builder, node_context, @global_state.index, dispatcher)
end

sig do
Expand Down

0 comments on commit 6279b37

Please sign in to comment.