Skip to content

Commit 7bc1bc5

Browse files
authored
Default uri path to localhost (#132)
1 parent 6cdf2c3 commit 7bc1bc5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/ruby_lsp/ruby_lsp_rails/rails_client.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def initialize
2828
url = URI(app_uri_path.read.chomp)
2929

3030
@ssl = T.let(url.scheme == "https", T::Boolean)
31-
@uri = T.let(T.must(url.path), T.nilable(String))
31+
@address = T.let(
32+
[url.host, url.path].reject { |component| component.nil? || component.empty? }.join("/"),
33+
T.nilable(String),
34+
)
3235
@port = T.let(T.must(url.port).to_i, Integer)
3336
end
3437
end
@@ -62,9 +65,9 @@ def check_if_server_is_running!
6265

6366
sig { params(path: String, timeout: T.nilable(Float)).returns(Net::HTTPResponse) }
6467
def request(path, timeout = nil)
65-
raise ServerAddressUnknown unless @uri
68+
raise ServerAddressUnknown unless @address
6669

67-
http = Net::HTTP.new(@uri, @port)
70+
http = Net::HTTP.new(@address, @port)
6871
http.use_ssl = @ssl
6972
http.read_timeout = timeout if timeout
7073
http.get("/ruby_lsp_rails/#{path}")

test/ruby_lsp_rails/rails_client_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ class RailsClientTest < ActiveSupport::TestCase
6262
RailsClient.new.check_if_server_is_running!
6363
end
6464
end
65+
66+
test "defaults path to localhost" do
67+
File.write("#{Dir.pwd}/test/dummy/tmp/app_uri.txt", "http://localhost:3000")
68+
69+
client = RailsClient.new
70+
assert_equal("localhost", client.instance_variable_get(:@address))
71+
assert_equal(3000, client.instance_variable_get(:@port))
72+
refute(client.instance_variable_get(:@ssl))
73+
end
6574
end
6675
end
6776
end

0 commit comments

Comments
 (0)