Skip to content

Commit cb8857a

Browse files
authored
Remove Sorbet from server.rb (#339)
* Remove Sorbet from `server.rb` * Use Bundler.with_original_env
1 parent 402f5d6 commit cb8857a

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/test/dummy/log/*.log
99
/test/dummy/storage/
1010
/test/dummy/tmp/
11+
gemfiles/*.lock

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Sorbet/StrictSigil:
3535
Exclude:
3636
- "**/*.rake"
3737
- "test/**/*.rb"
38+
- "lib/ruby_lsp/ruby_lsp_rails/server.rb" # we can't assume sorbet-runtime is available

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ def initialize
4848
# If we can't set the session ID, continue
4949
end
5050

51-
stdin, stdout, stderr, wait_thread = Open3.popen3(
52-
"bin/rails",
53-
"runner",
54-
"#{__dir__}/server.rb",
55-
"start",
56-
)
51+
stdin, stdout, stderr, wait_thread = Bundler.with_original_env do
52+
Open3.popen3("bin/rails", "runner", "#{__dir__}/server.rb", "start")
53+
end
54+
5755
@stdin = T.let(stdin, IO)
5856
@stdout = T.let(stdout, IO)
5957
@stderr = T.let(stderr, IO)

lib/ruby_lsp/ruby_lsp_rails/server.rb

+3-31
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
# typed: strict
1+
# typed: false
22
# frozen_string_literal: true
33

4-
require "sorbet-runtime"
54
require "json"
65

7-
begin
8-
T::Configuration.default_checked_level = :never
9-
# Suppresses call validation errors
10-
T::Configuration.call_validation_error_handler = ->(*) {}
11-
# Suppresses errors caused by T.cast, T.let, T.must, etc.
12-
T::Configuration.inline_type_error_handler = ->(*) {}
13-
# Suppresses errors caused by incorrect parameter ordering
14-
T::Configuration.sig_validation_error_handler = ->(*) {}
15-
rescue
16-
# Need this rescue so that if another gem has
17-
# already set the checked level by the time we
18-
# get to it, we don't fail outright.
19-
nil
20-
end
21-
226
# NOTE: We should avoid printing to stderr since it causes problems. We never read the standard error pipe from the
237
# client, so it will become full and eventually hang or crash. Instead, return a response with an `error` key.
248

@@ -27,16 +11,12 @@ module Rails
2711
class Server
2812
VOID = Object.new
2913

30-
extend T::Sig
31-
32-
sig { void }
3314
def initialize
3415
$stdin.sync = true
3516
$stdout.sync = true
36-
@running = T.let(true, T::Boolean)
17+
@running = true
3718
end
3819

39-
sig { void }
4020
def start
4121
initialize_result = { result: { message: "ok" } }.to_json
4222
$stdout.write("Content-Length: #{initialize_result.length}\r\n\r\n#{initialize_result}")
@@ -54,19 +34,13 @@ def start
5434
end
5535
end
5636

57-
sig do
58-
params(
59-
request: String,
60-
params: T.nilable(T::Hash[Symbol, T.untyped]),
61-
).returns(T.any(Object, T::Hash[Symbol, T.untyped]))
62-
end
6337
def execute(request, params)
6438
case request
6539
when "shutdown"
6640
@running = false
6741
VOID
6842
when "model"
69-
resolve_database_info_from_model(T.must(params).fetch(:name))
43+
resolve_database_info_from_model(params.fetch(:name))
7044
when "reload"
7145
::Rails.application.reloader.reload!
7246
VOID
@@ -79,7 +53,6 @@ def execute(request, params)
7953

8054
private
8155

82-
sig { params(model_name: String).returns(T::Hash[Symbol, T.untyped]) }
8356
def resolve_database_info_from_model(model_name)
8457
const = ActiveSupport::Inflector.safe_constantize(model_name)
8558
unless active_record_model?(const)
@@ -105,7 +78,6 @@ def resolve_database_info_from_model(model_name)
10578
{ error: e.full_message(highlight: false) }
10679
end
10780

108-
sig { params(const: T.untyped).returns(T::Boolean) }
10981
def active_record_model?(const)
11082
!!(
11183
const &&

0 commit comments

Comments
 (0)