Skip to content

Commit ef79527

Browse files
committed
Cleanup
1 parent 60af963 commit ef79527

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,18 @@ def initialize
2727
# We first initialize the client as a NullClient, so that we can start the server in a background thread. Until
2828
# the real client is initialized, features that depend on it will not be blocked by using the NullClient
2929
@client = T.let(NullClient.new, RunnerClient)
30+
@global_state = T.let(nil, T.nilable(GlobalState))
3031
end
3132

3233
sig { override.params(global_state: GlobalState, message_queue: Thread::Queue).void }
3334
def activate(global_state, message_queue)
34-
@global_state = T.let(global_state, T.nilable(RubyLsp::GlobalState))
35+
@global_state = global_state
3536
$stderr.puts("Activating Ruby LSP Rails addon v#{VERSION}")
3637
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
37-
Thread.new do
38-
@client = RunnerClient.create_client
39-
# TODO: move rails_runner_stdin to be in ruby-lsp instead of ivar_get
40-
# (or maybe somet other way, probably not in global state)
41-
@global_state.instance_variable_set(:@rails_runner_stdin, @client.stdin)
42-
end
38+
Thread.new { @client = RunnerClient.create_client(global_state) }
4339
register_additional_file_watchers(global_state: global_state, message_queue: message_queue)
4440

45-
T.must(@global_state).index.register_enhancement(IndexingEnhancement.new)
41+
@global_state.index.register_enhancement(IndexingEnhancement.new)
4642
end
4743

4844
sig { override.void }

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ class RunnerClient
1010
class << self
1111
extend T::Sig
1212

13-
sig { returns(RunnerClient) }
14-
def create_client
13+
sig do
14+
params(global_state: GlobalState).returns(RunnerClient)
15+
end
16+
def create_client(global_state)
1517
if File.exist?("bin/rails")
16-
new
18+
new(global_state)
1719
else
1820
$stderr.puts(<<~MSG)
1921
Ruby LSP Rails failed to locate bin/rails in the current directory: #{Dir.pwd}"
@@ -39,10 +41,11 @@ class EmptyMessageError < StandardError; end
3941
sig { returns(String) }
4042
attr_reader :rails_root
4143

44+
sig { returns(IO) }
4245
attr_reader :stdin
4346

44-
sig { void }
45-
def initialize
47+
sig { params(global_state: RubyLsp::GlobalState).void }
48+
def initialize(global_state)
4649
# Spring needs a Process session ID. It uses this ID to "attach" itself to the parent process, so that when the
4750
# parent ends, the spring process ends as well. If this is not set, Spring will throw an error while trying to
4851
# set its own session ID

0 commit comments

Comments
 (0)