Skip to content

Commit 308edfd

Browse files
authored
Merge pull request #37 from ruby/loaded_specs_types
Loads rbs defined in gem sig directory
2 parents 5bf206f + dfa4a78 commit 308edfd

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
@@ -253,6 +253,13 @@ def test_doc_namespace_error
253253
ReplTypeCompletor.instance_variable_set(:@last_completion_error, nil)
254254
end
255255

256+
def test_loaded_gem_types
257+
result = ReplTypeCompletor.analyze 'Prism.parse("code").', binding: binding
258+
candidtes = result.completion_candidates
259+
assert_includes candidtes, 'success?'
260+
assert_includes candidtes, 'failure?'
261+
end
262+
256263
def test_info
257264
assert_equal "ReplTypeCompletor: #{ReplTypeCompletor::VERSION}, Prism: #{Prism::VERSION}, RBS: #{RBS::VERSION}", ReplTypeCompletor.info
258265
end

0 commit comments

Comments
 (0)