Skip to content

Commit

Permalink
Pass index to enhancement's constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Oct 22, 2024
1 parent 1b2b113 commit ba3e595
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions lib/ruby_indexer/lib/ruby_indexer/enhancement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ class Enhancement

abstract!

sig { params(index: Index).void }
def initialize(index)
@index = index
end

# The `on_extend` indexing enhancement is invoked whenever an extend is encountered in the code. It can be used to
# register for an included callback, similar to what `ActiveSupport::Concern` does in order to auto-extend the
# `ClassMethods` modules
sig do
overridable.params(
index: Index,
owner: T.nilable(Entry::Namespace),
node: Prism::CallNode,
file_path: String,
Expand All @@ -23,11 +27,10 @@ class Enhancement
),
).void
end
def on_call_node_enter(index, owner, node, file_path, code_units_cache); end
def on_call_node_enter(owner, node, file_path, code_units_cache); end

sig do
overridable.params(
index: Index,
owner: T.nilable(Entry::Namespace),
node: Prism::CallNode,
file_path: String,
Expand All @@ -37,6 +40,6 @@ def on_call_node_enter(index, owner, node, file_path, code_units_cache); end
),
).void
end
def on_call_node_leave(index, owner, node, file_path, code_units_cache); end
def on_call_node_leave(owner, node, file_path, code_units_cache); end
end
end
8 changes: 4 additions & 4 deletions lib/ruby_indexer/test/enhancements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def on_call_node_enter(index, owner, node, file_path, code_units_cache)
end
end

@index.register_enhancement(enhancement_class.new)
@index.register_enhancement(enhancement_class.new(@index))
index(<<~RUBY)
module ActiveSupport
module Concern
Expand Down Expand Up @@ -124,7 +124,7 @@ def on_call_node_enter(index, owner, node, file_path, code_units_cache)
end
end

@index.register_enhancement(enhancement_class.new)
@index.register_enhancement(enhancement_class.new(@index))
index(<<~RUBY)
module ActiveSupport
module Concern
Expand Down Expand Up @@ -169,7 +169,7 @@ def name
end
end

@index.register_enhancement(enhancement_class.new)
@index.register_enhancement(enhancement_class.new(@index))

_stdout, stderr = capture_io do
index(<<~RUBY)
Expand Down Expand Up @@ -204,7 +204,7 @@ def name
end
end

@index.register_enhancement(enhancement_class.new)
@index.register_enhancement(enhancement_class.new(@index))

_stdout, stderr = capture_io do
index(<<~RUBY)
Expand Down

0 comments on commit ba3e595

Please sign in to comment.