lib/tapioca/helpers/rbi_files_helper.rb in tapioca-0.9.0 vs lib/tapioca/helpers/rbi_files_helper.rb in tapioca-0.9.1
- old
+ new
@@ -7,37 +7,37 @@
extend T::Helpers
requires_ancestor { Thor::Shell }
requires_ancestor { SorbetHelper }
- sig { params(index: RBI::Index, dir: String).void }
- def index_payload(index, dir)
- return unless Dir.exist?(dir)
-
- say("Loading Sorbet payload... ")
- files = Dir.glob("#{dir}/**/*.rbi").sort
- parse_and_index_files(index, files)
- say(" Done", :green)
- end
-
sig { params(index: RBI::Index, kind: String, file: String).void }
def index_rbi(index, kind, file)
return unless File.exist?(file)
say("Loading #{kind} RBIs from #{file}... ")
- parse_and_index_file(index, file)
- say(" Done", :green)
+ time = Benchmark.realtime do
+ parse_and_index_files(index, [file], number_of_workers: 1)
+ end
+ say(" Done ", :green)
+ say("(#{time.round(2)}s)")
end
- sig { params(index: RBI::Index, kind: String, dir: String).void }
- def index_rbis(index, kind, dir)
+ sig { params(index: RBI::Index, kind: String, dir: String, number_of_workers: T.nilable(Integer)).void }
+ def index_rbis(index, kind, dir, number_of_workers:)
return unless Dir.exist?(dir) && !Dir.empty?(dir)
- say("Loading #{kind} RBIs from #{dir}... ")
- files = Dir.glob("#{dir}/**/*.rbi").sort
- parse_and_index_files(index, files)
- say(" Done", :green)
+ if kind == "payload"
+ say("Loading Sorbet payload... ")
+ else
+ say("Loading #{kind} RBIs from #{dir}... ")
+ end
+ time = Benchmark.realtime do
+ files = Dir.glob("#{dir}/**/*.rbi").sort
+ parse_and_index_files(index, files, number_of_workers: number_of_workers)
+ end
+ say(" Done ", :green)
+ say("(#{time.round(2)}s)")
end
sig do
params(
index: RBI::Index,
@@ -46,17 +46,20 @@
).returns(T::Hash[String, T::Array[RBI::Node]])
end
def duplicated_nodes_from_index(index, shim_rbi_dir:, todo_rbi_file:)
duplicates = {}
say("Looking for duplicates... ")
- index.keys.each do |key|
- nodes = index[key]
- next unless shims_or_todos_have_duplicates?(nodes, shim_rbi_dir: shim_rbi_dir, todo_rbi_file: todo_rbi_file)
+ time = Benchmark.realtime do
+ index.keys.each do |key|
+ nodes = index[key]
+ next unless shims_or_todos_have_duplicates?(nodes, shim_rbi_dir: shim_rbi_dir, todo_rbi_file: todo_rbi_file)
- duplicates[key] = nodes
+ duplicates[key] = nodes
+ end
end
- say(" Done", :green)
+ say(" Done ", :green)
+ say("(#{time.round(2)}s)")
duplicates
end
sig { params(loc: RBI::Loc, path_prefix: T.nilable(String)).returns(String) }
def location_to_payload_url(loc, path_prefix:)
@@ -148,22 +151,22 @@
Kernel.exit(1) if parse_errors.any?
end
private
- sig { params(index: RBI::Index, files: T::Array[String]).void }
- def parse_and_index_files(index, files)
- files.each do |file|
- parse_and_index_file(index, file)
+ sig { params(index: RBI::Index, files: T::Array[String], number_of_workers: T.nilable(Integer)).void }
+ def parse_and_index_files(index, files, number_of_workers:)
+ executor = Executor.new(files, number_of_workers: number_of_workers)
+
+ trees = executor.run_in_parallel do |file|
+ next if Spoom::Sorbet::Sigils.file_strictness(file) == "ignore"
+
+ RBI::Parser.parse_file(file)
+ rescue RBI::ParseError => e
+ say_error("\nWarning: #{e} (#{e.location})", :yellow)
end
- end
- sig { params(index: RBI::Index, file: String).void }
- def parse_and_index_file(index, file)
- tree = RBI::Parser.parse_file(file)
- index.visit(tree)
- rescue RBI::ParseError => e
- say_error("\nWarning: #{e} (#{e.location})", :yellow)
+ index.visit_all(trees)
end
sig { params(nodes: T::Array[RBI::Node], shim_rbi_dir: String, todo_rbi_file: String).returns(T::Boolean) }
def shims_or_todos_have_duplicates?(nodes, shim_rbi_dir:, todo_rbi_file:)
return false if nodes.size == 1