Skip to content

Commit

Permalink
Merge pull request #15 from tk0miya/async_rbs_builder_loader
Browse files Browse the repository at this point in the history
Support loading types asynchronously
  • Loading branch information
tompng authored Jun 1, 2023
2 parents 253186d + e578679 commit 47f0ec0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/katakata_irb.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'katakata_irb/version'
require 'katakata_irb/completor'
require 'katakata_irb/types'

module KatakataIrb
class << self
Expand Down
22 changes: 21 additions & 1 deletion lib/katakata_irb/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@
module KatakataIrb; end
module KatakataIrb::Types
def self.rbs_builder
@rbs_builder ||= load_rbs_builder
preload if @rbs_builder.nil?

@rbs_builder
end

def self.loader_type=(loader_type)
@loader_type = loader_type
end

def self.preload
case @loader_type
when :sync, nil
@rbs_builder = load_rbs_builder
when :async
@loader_thread ||= Thread.new do
@rbs_builder = load_rbs_builder
end
end
rbs_builder_loader.run if @rbs_builder.nil?
end

def self.load_rbs_builder
Expand Down Expand Up @@ -59,6 +77,8 @@ def self.method_return_type(type, method_name)
end

def self.rbs_methods(type, method_name, args_types, kwargs_type, has_block)
return [] unless rbs_builder

receivers = type.types.map do |t|
case t
in ProcType
Expand Down

0 comments on commit 47f0ec0

Please sign in to comment.