Skip to content

Commit 36b8832

Browse files
committed
Set server pipes to binmode
1 parent 2947b77 commit 36b8832

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

lib/ruby_lsp/ruby_lsp_rails/definition.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def handle_route(node)
8888
result = @client.route_location(T.must(node.message))
8989
return unless result
9090

91-
file_path, line = result.fetch(:location).split(":")
91+
*file_parts, line = result.fetch(:location).split(":")
92+
file_path = file_parts.join(":")
9293

9394
@response_builder << Interface::Location.new(
9495
uri: URI::Generic.from_path(path: file_path).to_s,

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def initialize
8080
if @wait_thread.alive?
8181
$stderr.puts("Ruby LSP Rails is force killing the server")
8282
sleep(0.5) # give the server a bit of time if we already issued a shutdown notification
83-
Process.kill(T.must(Signal.list["TERM"]), @wait_thread.pid)
83+
Process.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
8484
end
8585
end
8686
end

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Server
1414
def initialize
1515
$stdin.sync = true
1616
$stdout.sync = true
17+
$stdin.binmode
18+
$stdout.binmode
1719
@running = true
1820
end
1921

test/ruby_lsp_rails/definition_test.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ def baz; end
8787

8888
assert_equal(1, response.size)
8989
dummy_root = File.expand_path("../dummy", __dir__)
90-
assert_equal("file://#{dummy_root}/config/routes.rb", response[0].uri)
90+
assert_equal(
91+
URI::Generic.from_path(path: File.join(dummy_root, "config", "routes.rb")).to_s,
92+
response[0].uri,
93+
)
9194
assert_equal(3, response[0].range.start.line)
9295
assert_equal(3, response[0].range.end.line)
9396
end
@@ -107,7 +110,10 @@ def baz; end
107110

108111
assert_equal(1, response.size)
109112
dummy_root = File.expand_path("../dummy", __dir__)
110-
assert_equal("file://#{dummy_root}/config/routes.rb", response[0].uri)
113+
assert_equal(
114+
URI::Generic.from_path(path: File.join(dummy_root, "config", "routes.rb")).to_s,
115+
response[0].uri,
116+
)
111117
assert_equal(4, response[0].range.start.line)
112118
assert_equal(4, response[0].range.end.line)
113119
end
@@ -132,7 +138,9 @@ def generate_definitions_for_source(source, position)
132138
params: { textDocument: { uri: uri }, position: position },
133139
)
134140

135-
server.pop_response.response
141+
result = server.pop_response
142+
assert_instance_of(RubyLsp::Result, result)
143+
result.response
136144
end
137145
end
138146
end

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
require "test_helper"
55
require "ruby_lsp/ruby_lsp_rails/runner_client"
66

7-
# tests are hanging in CI. https://github.com/Shopify/ruby-lsp-rails/issues/348
8-
return if Gem.win_platform?
9-
107
module RubyLsp
118
module Rails
129
class RunnerClientTest < ActiveSupport::TestCase
1310
setup do
14-
capture_subprocess_io do
15-
@client = T.let(RunnerClient.new, RunnerClient)
16-
end
11+
@client = T.let(RunnerClient.new, RunnerClient)
1712
end
1813

1914
teardown do
20-
capture_subprocess_io { @client.shutdown }
21-
assert_predicate @client, :stopped?
15+
@client.shutdown
16+
17+
# On Windows, the server process sometimes takes a lot longer to shutdown and may end up getting force killed,
18+
# which makes this assertion flaky
19+
assert_predicate(@client, :stopped?) unless Gem.win_platform?
2220
end
2321

2422
# These are integration tests which start the server. For the more fine-grained tests, see `server_test.rb`.

0 commit comments

Comments
 (0)