Skip to content
Open
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 @@ -283,6 +283,7 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-22
x86_64-linux
Expand Down
34 changes: 30 additions & 4 deletions app/models/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def visit_def(node)
elsif @modules.any?
@modules.last
else
@analyzer
inferred_context_for(target)
end

method_definition_args = {
Expand All @@ -143,10 +143,12 @@ def visit_def(node)
defined_files: [current_path],
}

if target == "self"
context.class_methods << ClassMethod.new(**method_definition_args)
else
# the method can define itself onto "self", or can have a target of a constant
# to define the class there. see #inferred_context_for for more
if target.nil?
context.instance_methods << InstanceMethod.new(**method_definition_args)
else
context.class_methods << ClassMethod.new(**method_definition_args)
end

@comments = []
Expand Down Expand Up @@ -188,4 +190,28 @@ def visit_command(node)

super
end

private

# handle method names like `Skiptrace.current_bindings` where the constant
# wasn't already visited
# rubocop:disable Lint/AssignmentInCondition
def inferred_context_for(target)
if existing = @analyzer.modules.detect { |name| name.qualified_name == target }
return prev if @modules.find { |mod| mod.qualified_name == existing.qualified_name }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is prev coming from? 🤔


@modules << existing
@namespace << existing
Comment on lines +203 to +204
Copy link
Copy Markdown
Owner

@marcoroth marcoroth Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't add it to the @modules or @namesapce since we are not going to traverse it's children, so we don't need to set setup it up to be part of the namespace, since we would also need to pop them again

return existing

elsif existing = @analyzer.classes.detect { |name| name.qualified_name == target }
return prev if @classes.find { |klass| klass.qualified_name == existing.qualified_name }

@classes << existing
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return existing

end
@analyzer
end
# rubocop:enable Lint/AssignmentInCondition
end