Skip to content

Commit dfa4a78

Browse files
committed
Load type information of required gems
1 parent 806645f commit dfa4a78

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/repl_type_completor/types.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'rbs'
4+
require 'rubygems'
45
require 'rbs/cli'
56
require_relative 'methods'
67

@@ -25,7 +26,13 @@ def self.preload_rbs_builder
2526
def self.load_rbs_builder
2627
@load_started = true
2728
loader = RBS::CLI::LibraryOptions.new.loader
28-
loader.add path: Pathname('sig')
29+
sig_path = Pathname('sig')
30+
loader.add path: sig_path
31+
expanded_sig_path = sig_path.expand_path.to_s
32+
Gem.loaded_specs.values.each do |spec|
33+
gem_sig_path = File.expand_path("#{spec.gem_dir}/sig")
34+
loader.add(library: spec.name, version: spec.version) if Dir.exist?(gem_sig_path) && expanded_sig_path != gem_sig_path
35+
end
2936
@rbs_builder = RBS::DefinitionBuilder.new env: RBS::Environment.from_loader(loader).resolve_type_names
3037
rescue LoadError, StandardError => e
3138
@rbs_load_error = e

test/repl_type_completor/test_repl_type_completor.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ def test_doc_namespace_error
236236
ReplTypeCompletor.instance_variable_set(:@last_completion_error, nil)
237237
end
238238

239+
def test_loaded_gem_types
240+
result = ReplTypeCompletor.analyze 'Prism.parse("code").', binding: binding
241+
candidtes = result.completion_candidates
242+
assert_includes candidtes, 'success?'
243+
assert_includes candidtes, 'failure?'
244+
end
245+
239246
def test_info
240247
assert_equal "ReplTypeCompletor: #{ReplTypeCompletor::VERSION}, Prism: #{Prism::VERSION}, RBS: #{RBS::VERSION}", ReplTypeCompletor.info
241248
end

0 commit comments

Comments
 (0)