Skip to content

Commit

Permalink
Enable rbs collection support
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke authored and mame committed Sep 21, 2021
1 parent 7338bd4 commit 921fa49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/typeprof/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def parse(argv)
gem_repo_dirs = []
show_version = false
max_sec = max_iter = nil
collection_path = RBS::Collection::Config::PATH

opt.separator ""
opt.separator "Options:"
Expand All @@ -33,6 +34,8 @@ def parse(argv)
opt.on("-I DIR", "Add DIR to the load/require path") {|v| $LOAD_PATH << v }
opt.on("-r FEATURE", "Require RBS of the FEATURE gem") {|v| gem_rbs_features << v }
opt.on("--repo DIR", "Add DIR to the RBS repository") {|v| gem_repo_dirs << v }
opt.on("--collection PATH", "File path of collection configuration") { |v| collection_path = v }
opt.on("--no-collection", "Ignore collection configuration") { collection_path = nil }

opt.separator ""
opt.separator "Analysis output options:"
Expand Down Expand Up @@ -93,6 +96,7 @@ def parse(argv)
output: output,
gem_rbs_features: gem_rbs_features,
gem_repo_dirs: gem_repo_dirs,
collection_path: collection_path,
verbose: verbose,
dir_filter: dir_filter,
max_sec: max_sec,
Expand Down
4 changes: 4 additions & 0 deletions lib/typeprof/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module TypeProf
:output,
:gem_rbs_features,
:gem_repo_dirs,
:collection_path,
:verbose,
:dir_filter,
:max_iter,
Expand Down Expand Up @@ -81,6 +82,9 @@ def self.analyze(config)
Import.import_library(scratch, feature)
end

collection_path = config.collection_path
Import.import_rbs_collection(scratch, collection_path) if collection_path&.exist?

rbs_files = []
rbs_codes = []
Config.rbs_files.each do |rbs|
Expand Down
12 changes: 12 additions & 0 deletions lib/typeprof/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def load_rbs_string(name, content)
RBSReader.load_rbs(@env, new_decls)
end

def load_rbs_collection(collection_path)
loader = RBS::EnvironmentLoader.new(core_root: nil)
collection_lock = RBS::Collection::Config.lockfile_of(collection_path)
loader.add_collection(collection_lock)
new_decls = loader.load(env: @env).map {|decl,| decl }
RBSReader.load_rbs(@env, new_decls)
end

def self.load_rbs(env, new_decls)
all_env = env.resolve_type_names
resolver = RBS::TypeNameResolver.from_env(all_env)
Expand Down Expand Up @@ -514,6 +522,10 @@ def self.import_rbs_code(scratch, rbs_name, rbs_code)
Import.new(scratch, scratch.rbs_reader.load_rbs_string(rbs_name, rbs_code)).import(true)
end

def self.import_rbs_collection(scratch, collection_path)
Import.new(scratch, scratch.rbs_reader.load_rbs_collection(collection_path)).import(true)
end

def initialize(scratch, json)
@scratch = scratch
@json = json
Expand Down

0 comments on commit 921fa49

Please sign in to comment.