Skip to content

Commit

Permalink
Merge pull request #44 from ruby/tracepoint_thread_pass
Browse files Browse the repository at this point in the history
Use Thread.pass within TracePoint hook to improve REPL responce
  • Loading branch information
tompng authored Dec 12, 2024
2 parents cbb2cfb + 1e44839 commit 1a87909
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/repl_type_completor/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def self.load_rbs_builder
end
end

env = RBS::Environment.from_loader(loader)
# [Hack] Monkey patch for improving development experience
def env.resolve_declaration(*, **)
Thread.pass
super
# Hack to make this thread priority lower, not to block the main thread.
thread_pass_counter = 0
tracepoint = TracePoint.new(:call) do
Thread.pass if ((thread_pass_counter += 1) % 10).zero?
end
tracepoint.enable do
env = RBS::Environment.from_loader(loader)
@rbs_builder = RBS::DefinitionBuilder.new env: env.resolve_type_names
end
@rbs_builder = RBS::DefinitionBuilder.new env: env.resolve_type_names
rescue LoadError, StandardError => e
@rbs_load_error = e
nil
Expand Down

0 comments on commit 1a87909

Please sign in to comment.