diff --git a/Gemfile.lock b/Gemfile.lock index b13022f8cd..df6352763f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -176,6 +176,7 @@ GEM zlib (3.2.1) PLATFORMS + ruby DEPENDENCIES abbrev diff --git a/lib/rbs/environment.rb b/lib/rbs/environment.rb index 762dce5bec..64bfd6da9f 100644 --- a/lib/rbs/environment.rb +++ b/lib/rbs/environment.rb @@ -495,7 +495,7 @@ def resolve_type_names(only: nil) each_rbs_source do |source| resolve = source.directives.find { _1.is_a?(AST::Directives::ResolveTypeNames) } #: AST::Directives::ResolveTypeNames? if !resolve || resolve.value - _, decls = resolve_signature(resolver, table, source.directives, source.declarations) + _, decls = resolve_signature(resolver, table, source.directives, source.declarations, only: only) else decls = source.declarations end @@ -504,7 +504,15 @@ def resolve_type_names(only: nil) each_ruby_source do |source| decls = source.declarations.map do |decl| - resolve_ruby_decl(resolver, decl, context: nil, prefix: Namespace.root) + if only + if only.include?(decl) + resolve_ruby_decl(resolver, decl, context: nil, prefix: Namespace.root) + else + decl + end + else + resolve_ruby_decl(resolver, decl, context: nil, prefix: Namespace.root) + end end env.add_source(Source::Ruby.new(source.buffer, source.prism_result, decls, source.diagnostics)) @@ -845,7 +853,7 @@ def absolute_type(resolver, map, type, context:) end def inspect - ivars = %i[@declarations @class_decls @class_alias_decls @interface_decls @type_alias_decls @constant_decls @global_decls] + ivars = %i[@sources @class_decls @class_alias_decls @interface_decls @type_alias_decls @constant_decls @global_decls] "\#" end @@ -853,12 +861,25 @@ def buffers sources.map(&:buffer) end - def unload(buffers) - env = Environment.new - bufs = buffers.to_set + def unload(paths) + ps = Set[] + paths.each do |path| + if path.is_a?(Buffer) + ps << path.name + else + ps << path + end + end + + env = Environment.new() each_rbs_source do |source| - next if bufs.include?(source.buffer) + next if ps.include?(source.buffer.name) + env.add_source(source) + end + + each_ruby_source do |source| + next if ps.include?(source.buffer.name) env.add_source(source) end diff --git a/sig/environment.rbs b/sig/environment.rbs index e25f912d46..e88a617f71 100644 --- a/sig/environment.rbs +++ b/sig/environment.rbs @@ -84,9 +84,15 @@ module RBS # When `only` is given, it skips other _top-level_ declarations not included in the collection. # This helps running resolution faster in the case of _partial updates_. # - def resolve_type_names: (?only: Set[AST::Declarations::t]?) -> Environment + def resolve_type_names: (?only: Set[AST::Declarations::t | AST::Ruby::Declarations::t]?) -> Environment - def resolve_signature: (Resolver::TypeNameResolver, UseMap::Table, Array[AST::Directives::t], Array[AST::Declarations::t], ?only: Set[AST::Declarations::t]?) -> [Array[AST::Directives::t], Array[AST::Declarations::t]] + def resolve_signature: ( + Resolver::TypeNameResolver, + UseMap::Table, + Array[AST::Directives::t], + Array[AST::Declarations::t], + ?only: Set[AST::Declarations::t | AST::Ruby::Declarations::t]? + ) -> [Array[AST::Directives::t], Array[AST::Declarations::t]] def inspect: () -> String @@ -94,7 +100,8 @@ module RBS # Remove declarations and directives that are loaded from `buffers` # - def unload: (Set[Buffer] buffers) -> Environment + def unload: (Set[Pathname] paths) -> Environment + | %a{deprecated: Use pathname version} (Set[Buffer] buffers) -> Environment # Returns true if an interface with the type name is defined # diff --git a/sig/source.rbs b/sig/source.rbs index befbc352c6..c18906845f 100644 --- a/sig/source.rbs +++ b/sig/source.rbs @@ -1,7 +1,7 @@ module RBS module Source type t = RBS | Ruby - + class RBS attr_reader buffer: Buffer @@ -28,9 +28,9 @@ module RBS attr_reader declarations: Array[AST::Ruby::Declarations::t] - attr_reader diagnostics: Array[untyped] + attr_reader diagnostics: Array[InlineParser::Diagnostic::t] - def initialize: (Buffer, Prism::ParseResult, Array[AST::Ruby::Declarations::t], Array[untyped]) -> void + def initialize: (Buffer, Prism::ParseResult, Array[AST::Ruby::Declarations::t], Array[InlineParser::Diagnostic::t]) -> void def each_type_name: () { (TypeName) -> void } -> void | () -> Enumerator[TypeName]