Skip to content

Conversation

@vicocamacho
Copy link

@vicocamacho vicocamacho commented Nov 4, 2025

close #361

image

@vicocamacho vicocamacho requested a review from a team as a code owner November 4, 2025 20:23
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Let's just change the way that the stack related things are being handled. Other than that, the change looks good


return unless node.parent.name == :ActiveRecord && node.name == :Schema

@namespace_stack << node.full_name
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't push this to the namespace stack. The goal of the stack is to remember the module/class nesting that we're currently inside.

Originally, we needed to return early if the stack was empty, but this addition changes that premise.

Let's do the following:

def on_call_node_enter(node)
  message = node.message
  return unless message

  # Handle the tables here
  handle_schema_table(node)

  receiver = node.receiver
  return if receiver && !receiver.is_a?(Prism::SelfNode)

  # Handle cases that require being inside a certain level of nesting
  return if @namespace_stack.empty?
  
  case message
  when *Support::Callbacks::ALL, "validate"
    handle_all_arg_types(node, message)
  when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many", "has_and_belongs_to_many", "attr_readonly", "scope"
    handle_symbol_and_string_arg_types(node, message)
  when "validates_with"
    handle_class_arg_types(node, message)
  when "create_table"
    handle_create_table(node)
  else
    content = extract_test_case_name(node)

    if content
      append_document_symbol(
        name: content,
        selection_range: range_from_node(node),
        range: range_from_node(node),
      )
    end
  end
end

Copy link
Author

@vicocamacho vicocamacho Nov 12, 2025

Choose a reason for hiding this comment

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

hey @vinistock, thanks for the feedback. I'm almost done incorporating it.

I just have one quick question about this, don't we need to check that we are inside the ActiveRecord::Schema#define block before adding the symbols? If this is correct I'm not sure how to do that without using the namespace stack.

Otherwise calling create_table from anywhere will append to the symbols which doesn't seem right to me.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's a good point. We can definitely check for the ActiveRecord::Schema#define call, but let's simply remember this state separately in another instance variable.

For example:

def initialize(...)
  # ...

  @inside_schema = false #: bool
end

def on_call_node_enter(node)
  # ...
  @inside_schema = true if message == "define" && constant_name(receiver) == "ActiveRecord::Schema"
end

def on_call_node_leave(node)
  # ...
  @inside_schema = false if message == "define" && constant_name(receiver) == "ActiveRecord::Schema"
end

Copy link
Author

Choose a reason for hiding this comment

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

@vinistock this should be good to go. I added a test case to guard us against the create_table method adding symbols outside the ActiveRecord::Schema#define block. Please let me know of any other feedback.

@vinistock vinistock added the enhancement New feature or request label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document symbol support for schema.rb

3 participants