lib/rbs/environment.rb in rbs-3.0.0.dev.3 vs lib/rbs/environment.rb in rbs-3.0.0

- old
+ new

@@ -8,12 +8,13 @@ attr_reader :interface_decls attr_reader :type_alias_decls attr_reader :constant_decls attr_reader :global_decls attr_reader :class_alias_decls - attr_reader :buffer_directives + attr_reader :signatures + module ContextUtil def calculate_context(decls) decls.inject(nil) do |context, decl| #$ Resolver::context if (_, last = context) last or raise @@ -140,34 +141,32 @@ class GlobalEntry < SingleEntry end def initialize - @buffers = [] + @signatures = {} @declarations = [] @class_decls = {} @interface_decls = {} @type_alias_decls = {} @constant_decls = {} @global_decls = {} @class_alias_decls = {} @normalize_module_name_cache = {} - @buffer_directives = {} end def initialize_copy(other) - @buffers = other.buffers.dup + @signatures = other.signatures.dup @declarations = other.declarations.dup @class_decls = other.class_decls.dup @interface_decls = other.interface_decls.dup @type_alias_decls = other.type_alias_decls.dup @constant_decls = other.constant_decls.dup @global_decls = other.global_decls.dup @class_alias_decls = other.class_alias_decls.dup - @buffer_directives = other.buffer_directives.dup end def self.from_loader(loader) self.new.tap do |env| loader.load(env: env) @@ -427,11 +426,11 @@ insert_decl(decl, outer: [], namespace: Namespace.root) self end def add_signature(buffer:, directives:, decls:) - buffer_directives[buffer] = directives + signatures[buffer] = [directives, decls] decls.each do |decl| self << decl end end @@ -450,13 +449,11 @@ table.known_types.merge(class_alias_decls.keys) table.known_types.merge(type_alias_decls.keys) table.known_types.merge(interface_decls.keys) table.compute_children - buffers_decls.each do |buffer, decls| - dirs = buffer_directives.fetch(buffer) - + signatures.each do |buffer, (dirs, decls)| map = UseMap.new(table: table) dirs.each do |dir| dir.clauses.each do |clause| map.build_map(clause) end @@ -756,31 +753,17 @@ ivars = %i[@declarations @class_decls @class_alias_decls @interface_decls @type_alias_decls @constant_decls @global_decls] "\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>" end def buffers - buffers_decls.keys.compact + signatures.keys end - def buffers_decls - # @type var hash: Hash[Buffer, Array[AST::Declarations::t]] - hash = {} - - declarations.each do |decl| - location = decl.location or next - (hash[location.buffer] ||= []) << decl - end - - hash - end - def unload(buffers) env = Environment.new - buffers_decls.each do |buf, decls| + signatures.each do |buf, (dirs, decls)| next if buffers.include?(buf) - - dirs = buffer_directives.fetch(buf) env.add_signature(buffer: buf, directives: dirs, decls: decls) end env end