Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable rbs collection support #53

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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