Skip to content

Commit

Permalink
Merge main (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 24, 2025
2 parents 31d6cb8 + 45835f2 commit 4af613e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/ruby_lsp/tapioca/server_addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "tapioca/dsl/compilers/url_helpers"
require "tapioca/dsl/compilers/active_record_fixtures"
require "active_support/test_case" # need?
require "tapioca/dsl/compilers/url_helpers"

module RubyLsp
module Tapioca
Expand Down
42 changes: 24 additions & 18 deletions spec/tapioca/addon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AddonSpec < Minitest::HooksSpec
request_name: "dsl",
constants: ["NotifyUserJob"],
)
wait_until_exists("spec/dummy/sorbet/rbi/dsl/notify_user_job.rbi")

shutdown_client

assert_path_exists("spec/dummy/sorbet/rbi/dsl/notify_user_job.rbi")
Expand Down Expand Up @@ -55,6 +57,7 @@ class AddonSpec < Minitest::HooksSpec
type: Constant::FileChangeType::CREATED,
}])

wait_until_exists("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi")
shutdown_client

assert_match("rails_info_routes_path", File.read("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi"))
Expand All @@ -64,7 +67,7 @@ class AddonSpec < Minitest::HooksSpec
FileUtils.rm("spec/dummy/config/routes.rb") if File.exist?("spec/dummy/config/routes.rb")
end

it "triggers fixtures DSL generation if fixtures are modified" do
it "trigger fixtures DSL generate if a fixture is modified" do
create_client

global_state = RubyLsp::GlobalState.new
Expand All @@ -82,19 +85,24 @@ class AddonSpec < Minitest::HooksSpec
addon.instance_variable_set(:@index, global_state.index)
addon.instance_variable_set(:@outgoing_queue, @outgoing_queue)

File.write("test/fixtures/foo.yml", "")
# TODO create test/fixtures ?
File.write("test/fixtures/users.yml", <<~RUBY)
# contents?
RUBY

addon.workspace_did_change_watched_files([{
uri: "file://#{Dir.pwd}/test/fixtures/foo.yml",
uri: "file://#{Dir.pwd}/test/fixtures/users.yml",
type: Constant::FileChangeType::CREATED,
}])

wait_until_exists("spec/dummy/sorbet/rbi/dsl/active_record/test_fixtures.rbi")
shutdown_client

assert_match("def foo", File.read("spec/dummy/sorbet/rbi/dsl/generated_url_helpers_module.rbi"))
# assert_match("rails_info_routes_path", File.read("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi"))
# assert_match("rails_info_routes_url", File.read("spec/dummy/sorbet/rbi/dsl/generated_url_helpers_module.rbi"))
ensure
# FileUtils.rm_rf("spec/dummy/sorbet/rbi") # TODO: fix path
FileUtils.rm("test/fixtures/foo.yml") if File.exist?("test/fixtures/foo.yml")
# FileUtils.rm_rf("spec/dummy/sorbet/rbi")
FileUtils.rm("test/fixtures/users.yml") if File.exist?("test/fixtures/users.yml")
end

private
Expand All @@ -117,22 +125,20 @@ def create_client

# Triggers shutdown and waits for it to complete
def shutdown_client
Thread.new do
@client.shutdown
@client.instance_variable_get(:@wait_thread).join

begin
# Since the Tapioca server add-on forks, there are no guarantees that the forked process will finish while
# we shutdown the client. We need to make sure the child processes are done before continuing
Process.wait
rescue Errno::ECHILD
# The forked process finished before we waited
end
end.join
@client.shutdown
@client.instance_variable_get(:@wait_thread).join

assert_predicate(@client, :stopped?)
@outgoing_queue.close
end

def wait_until_exists(path)
Timeout.timeout(4) do
sleep(0.2) until File.exist?(path)
end
rescue Timeout::Error
flunk("#{path} was not created in time")
end
end
end
end

0 comments on commit 4af613e

Please sign in to comment.