Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Environment#unload, remove #reject #1236

Merged
merged 1 commit into from
Feb 14, 2023
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
11 changes: 6 additions & 5 deletions lib/rbs/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,14 @@ def buffers_decls
hash
end

def reject
def unload(buffers)
env = Environment.new

declarations.each do |decl|
unless yield(decl)
env << decl
end
buffers_decls.each do |buf, decls|
next if buffers.include?(buf)

dirs = buffer_directives.fetch(buf)
env.add_signature(buffer: buf, directives: dirs, decls: decls)
end

env
Expand Down
5 changes: 2 additions & 3 deletions sig/environment.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ module RBS

def buffers_decls: () -> Hash[Buffer, Array[AST::Declarations::t]]

# Construct new environment without declarations tested `true` by block.
# Construction of new environment is done with `<<` so that nested declarations will work well.
# Remove declarations and directives that are loaded from `buffers`
#
def reject: () { (AST::Declarations::t) -> boolish } -> Environment
def unload: (Set[Buffer] buffers) -> Environment

# Returns true if an interface with the type name is defined
#
Expand Down
34 changes: 0 additions & 34 deletions test/rbs/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,40 +437,6 @@ class C
end
end

def test_reject
env = Environment.new

foo = RBS::Buffer.new(content: <<EOF, name: Pathname("foo.rbs"))
class Hello < String
def hello: (String) -> Integer
end
EOF

RBS::Parser.parse_signature(foo)[2].each do |decl|
env << decl
end

bar = RBS::Buffer.new(content: <<EOF, name: Pathname("bar.rbs"))
class Hello
def world: () -> void
end
EOF

RBS::Parser.parse_signature(bar)[2].each do |decl|
env << decl
end

assert env.buffers.any? {|buf| buf.name == Pathname("foo.rbs") }
assert env.buffers.any? {|buf| buf.name == Pathname("bar.rbs") }

env_ = env.reject do |decl|
decl.location.buffer.name == Pathname("foo.rbs")
end

assert env_.buffers.none? {|buf| buf.name == Pathname("foo.rbs") }
assert env_.buffers.any? {|buf| buf.name == Pathname("bar.rbs") }
end

def test_absolute_type_generics_upper_bound
env = Environment.new

Expand Down