Skip to content

Commit

Permalink
Make instanec of RunnerClient accessible for addons
Browse files Browse the repository at this point in the history
  • Loading branch information
johansenja committed Oct 2, 2024
1 parent 4730303 commit 9a94247
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
module RubyLsp
module Rails
class RunnerClient
@instance = T.let(nil, T.nilable(RunnerClient))

class << self
extend T::Sig

sig { returns(T.nilable(RunnerClient)) }
attr_reader :instance

sig { returns(RunnerClient) }
def create_client
if File.exist?("bin/rails")
new
@instance = new
else
$stderr.puts(<<~MSG)
Ruby LSP Rails failed to locate bin/rails in the current directory: #{Dir.pwd}"
MSG
$stderr.puts("Server dependent features will not be available")
NullClient.new
@instance = NullClient.new
end
rescue Errno::ENOENT, StandardError => e # rubocop:disable Lint/ShadowedException
$stderr.puts("Ruby LSP Rails failed to initialize server: #{e.message}\n#{e.backtrace&.join("\n")}")
$stderr.puts("Server dependent features will not be available")
NullClient.new
@instance = NullClient.new
end
end

Expand Down Expand Up @@ -169,6 +174,22 @@ def stopped?
[@stdin, @stdout, @stderr].all?(&:closed?) && !@wait_thread.alive?
end

sig do
params(
server_addon_name: String,
request_name: String,
params: T.nilable(T::Hash[Symbol, T.untyped])
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
end
def make_addon_request(server_addon_name, request_name, **params)
make_request(
"server_addon/delegate",
server_addon_name:,
request_name:,
**params
)
end

sig do
params(
request: String,
Expand Down

0 comments on commit 9a94247

Please sign in to comment.