lib/rbs/diff.rb in rbs-3.3.0.pre.2 vs lib/rbs/diff.rb in rbs-3.3.0

- old
+ new

@@ -10,17 +10,17 @@ end def each_diff(&block) return to_enum(:each_diff) unless block - before_instance_methods, before_singleton_methods, before_constant_decls = build_methods(@before_path) - after_instance_methods, after_singleton_methods, after_constant_decls = build_methods(@after_path) + before_instance_methods, before_singleton_methods, before_constant_children = build_methods(@before_path) + after_instance_methods, after_singleton_methods, after_constant_children = build_methods(@after_path) each_diff_methods(:instance, before_instance_methods, after_instance_methods, &block) each_diff_methods(:singleton, before_singleton_methods, after_singleton_methods, &block) - each_diff_constants(before_constant_decls, after_constant_decls, &block) + each_diff_constants(before_constant_children, after_constant_children, &block) end private def each_diff_methods(kind, before_methods, after_methods) @@ -32,15 +32,15 @@ yield before, after end end - def each_diff_constants(before_constant_decls, after_constant_decls) - all_keys = before_constant_decls.keys.to_set + after_constant_decls.keys.to_set + def each_diff_constants(before_constant_children, after_constant_children) + all_keys = before_constant_children.keys.to_set + after_constant_children.keys.to_set all_keys.each do |key| - before = constant_to_s(key, before_constant_decls[key]) or next - after = constant_to_s(key, after_constant_decls[key]) or next + before = constant_to_s(before_constant_children[key]) or next + after = constant_to_s(after_constant_children[key]) or next next if before == after yield before, after end end @@ -50,29 +50,46 @@ builder = build_builder(env) instance_methods = begin builder.build_instance(@type_name).methods rescue => e - RBS.logger.warn("#{path}: #{e.message}") + RBS.logger.warn("#{path}: (#{e.class}) #{e.message}") {} end singleton_methods = begin builder.build_singleton(@type_name).methods rescue => e - RBS.logger.warn("#{path}: #{e.message}") + RBS.logger.warn("#{path}: (#{e.class}) #{e.message}") {} end - type_name_to_s = @type_name.to_s - constant_decls = env.constant_decls.select { |key| key.to_s.start_with?(type_name_to_s) } - [ instance_methods, singleton_methods, constant_decls ] + constant_children = begin + constant_resolver = RBS::Resolver::ConstantResolver.new(builder: builder) + constant_resolver.children(@type_name) + rescue => e + RBS.logger.warn("#{path}: (#{e.class}) #{e.message}") + {} + end + + [ instance_methods, singleton_methods, constant_children ] end def build_env(path) loader = @library_options.loader() path&.each do |dir| - loader.add(path: Pathname(dir)) + dir_pathname = Pathname(dir) + loader.add(path: dir_pathname) + + manifest_pathname = dir_pathname / 'manifest.yaml' + if manifest_pathname.exist? + manifest = YAML.safe_load(manifest_pathname.read) + if manifest['dependencies'] + manifest['dependencies'].each do |dependency| + loader.add(library: dependency['name'], version: nil) + end + end + end end Environment.from_loader(loader) end def build_builder(env) @@ -91,12 +108,12 @@ else +"-" end end - def constant_to_s(key, constant) + def constant_to_s(constant) if constant - "#{key}: #{constant.decl.type}" + "#{constant.name.name}: #{constant.type}" else +"-" end end end