Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tapioca Add-on] Trigger DSL generation upon file changes #2031

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ gem "irb"
gem "rubocop-shopify"
gem "rubocop-sorbet", ">= 0.4.1"
gem "rubocop-rspec"
gem "ruby-lsp", ">= 0.19.0"
gem "ruby-lsp-rails", ">= 0.3.17"
gem "ruby-lsp", ">= 0.19.1"
gem "ruby-lsp-rails", ">= 0.3.18"

group :deployment, :development do
gem "rake"
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ GEM
rubocop (~> 1.51)
rubocop-sorbet (0.8.5)
rubocop (>= 1)
ruby-lsp (0.19.0)
ruby-lsp (0.19.1)
language_server-protocol (~> 3.17.0)
prism (>= 1.1, < 2.0)
rbs (>= 3, < 4)
sorbet-runtime (>= 0.5.10782)
ruby-lsp-rails (0.3.17)
ruby-lsp-rails (0.3.18)
ruby-lsp (>= 0.19.0, < 0.20.0)
ruby-progressbar (1.13.0)
shopify-money (3.0.0)
Expand Down Expand Up @@ -394,8 +394,8 @@ DEPENDENCIES
rubocop-rspec
rubocop-shopify
rubocop-sorbet (>= 0.4.1)
ruby-lsp (>= 0.19.0)
ruby-lsp-rails (>= 0.3.17)
ruby-lsp (>= 0.19.1)
ruby-lsp-rails (>= 0.3.18)
shopify-money
sidekiq
smart_properties
Expand Down
22 changes: 21 additions & 1 deletion lib/ruby_lsp/tapioca/addon.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: strict
# frozen_string_literal: true

RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.19", "< 0.20")
RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.19.1", "< 0.20")

begin
# The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the
Expand All @@ -25,13 +25,15 @@ def initialize

@global_state = T.let(nil, T.nilable(RubyLsp::GlobalState))
@rails_runner_client = T.let(nil, T.nilable(RubyLsp::Rails::RunnerClient))
@index = T.let(nil, T.nilable(RubyIndexer::Index))
KaanOzkan marked this conversation as resolved.
Show resolved Hide resolved
end

sig { override.params(global_state: RubyLsp::GlobalState, outgoing_queue: Thread::Queue).void }
def activate(global_state, outgoing_queue)
@global_state = global_state
return unless @global_state.experimental_features

@index = @global_state.index
Thread.new do
# Get a handle to the Rails add-on's runtime client. The call to `rails_runner_client` will block this thread
# until the server has finished booting, but it will not block the main LSP. This has to happen inside of a
Expand Down Expand Up @@ -60,6 +62,24 @@ def version

sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
def workspace_did_change_watched_files(changes)
constants = changes.flat_map do |change|
path = URI(change[:uri]).to_standardized_path
entries = T.must(@index).entries_for(path)
next unless entries
KaanOzkan marked this conversation as resolved.
Show resolved Hide resolved

entries.filter_map do |entry|
entry.name if entry.class == RubyIndexer::Entry::Class || entry.class == RubyIndexer::Entry::Module
end
end

return if constants.empty?

T.must(@rails_runner_client).trigger_reload
T.must(@rails_runner_client).delegate_notification(
server_addon_name: "Tapioca",
request_name: "dsl",
params: { constants: constants },
)
end
end
end
Expand Down
Loading
Loading