Skip to content
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ GEM
zlib (3.2.1)

PLATFORMS
ruby

DEPENDENCIES
abbrev
Expand Down
35 changes: 28 additions & 7 deletions lib/rbs/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -845,20 +853,33 @@ 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]
"\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>"
end

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

Expand Down
13 changes: 10 additions & 3 deletions sig/environment.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,24 @@ 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

def buffers: () -> Array[Buffer]

# 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
#
Expand Down
6 changes: 3 additions & 3 deletions sig/source.rbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RBS
module Source
type t = RBS | Ruby

class RBS
attr_reader buffer: Buffer

Expand All @@ -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]
Expand Down