Skip to content

Commit f093d7a

Browse files
committed
wip
1 parent a600e02 commit f093d7a

35 files changed

+4877
-4892
lines changed

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,9 @@ See the [documentation](https://shopify.github.io/ruby-lsp-rails) for more in-de
5252
5353
## How It Works
5454

55-
This gem consists of two components that enable enhanced Rails functionality in the editor:
56-
57-
1. A Rack app that automatically exposes APIs when Rails server is running
58-
1. A Ruby LSP addon that connects to the exposed APIs to fetch runtime information from the Rails server
59-
60-
This is why the Rails server needs to be running for some features to work.
61-
62-
> [!NOTE]
63-
> There is no need to restart the Ruby LSP every time the Rails server is booted.
64-
> If the server is shut down, the extra features will temporarily disappear and reappear once the server is running again.
55+
When Ruby LSP Rails starts, it spawns a `rails runner` instance which runs
56+
`[server.rb](https://github.com/Shopify/ruby-lsp-rails/blob/main/lib/ruby_lsp/ruby_lsp_rails/server.rb)`.
57+
The addon communicates with this process over a pipe (i.e. stdin/stdout) to fetch runtime information about the Rails application.
6558

6659
## Contributing
6760

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
require "ruby_lsp/addon"
55

6-
require_relative "rails_client"
6+
require_relative "runner_client"
77
require_relative "hover"
88
require_relative "code_lens"
99

@@ -12,18 +12,20 @@ module Rails
1212
class Addon < ::RubyLsp::Addon
1313
extend T::Sig
1414

15-
sig { returns(RailsClient) }
15+
sig { returns(RunnerClient) }
1616
def client
17-
@client ||= T.let(RailsClient.new, T.nilable(RailsClient))
17+
@client ||= T.let(RunnerClient.new, T.nilable(RunnerClient))
1818
end
1919

2020
sig { override.params(message_queue: Thread::Queue).void }
2121
def activate(message_queue)
22-
client.check_if_server_is_running!
22+
# @client ||= T.let(RunnerClient.new, T.nilable(RunnerClient))
2323
end
2424

2525
sig { override.void }
26-
def deactivate; end
26+
def deactivate
27+
T.must(@client).shutdown
28+
end
2729

2830
# Creates a new CodeLens listener. This method is invoked on every CodeLens request
2931
sig do

lib/ruby_lsp/ruby_lsp_rails/hover.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Hover
2222

2323
sig do
2424
params(
25-
client: RailsClient,
25+
client: RunnerClient,
2626
response_builder: ResponseBuilders::Hover,
2727
nesting: T::Array[String],
2828
index: RubyIndexer::Index,

lib/ruby_lsp_rails/rack_app.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

lib/ruby_lsp_rails/railtie.rb

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,23 @@
22
# frozen_string_literal: true
33

44
require "rails"
5-
require "ruby_lsp_rails/rack_app"
65

76
module RubyLsp
87
module Rails
98
class Railtie < ::Rails::Railtie
109
config.ruby_lsp_rails = ActiveSupport::OrderedOptions.new
11-
config.ruby_lsp_rails.server = true
10+
# TODO: should we allow the runner to be enabled/disabled?
11+
# config.ruby_lsp_rails.runner = true
1212

1313
initializer "ruby_lsp_rails.setup" do |_app|
14-
config.after_initialize do |app|
15-
# If we start the app with `bin/rails console` then `Rails::Server` is not defined.
16-
if defined?(::Rails::Server) && config.ruby_lsp_rails.server
17-
app.routes.prepend do
18-
T.bind(self, ActionDispatch::Routing::Mapper)
19-
mount(RackApp.new => RackApp::BASE_PATH)
20-
end
21-
22-
ssl_enable, host, port = ::Rails::Server::Options.new.parse!(ARGV).values_at(:SSLEnable, :Host, :Port)
23-
app_uri = "#{ssl_enable ? "https" : "http"}://#{host}:#{port}"
24-
app_uri_path = ::Rails.root.join("tmp", "app_uri.txt")
25-
app_uri_path.write(app_uri)
14+
config.after_initialize do |_app|
15+
if config.ruby_lsp_rails.server
16+
# TODO: confirm text
17+
raise "The `config.ruby_lsp_rails.server` configuration option is no longer needed"
18+
end
2619

27-
at_exit do
28-
# The app_uri.txt file should only exist when the server is running. The addon uses its presence to
29-
# report if the server is running or not. If the server is not running, some of the addon features
30-
# will not be available.
31-
File.delete(app_uri_path) if File.exist?(app_uri_path)
32-
end
20+
at_exit do
21+
# TBC
3322
end
3423
end
3524
end

0 commit comments

Comments
 (0)