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

Fix comments parsing for RBI::Method #333

Merged
merged 1 commit into from
Aug 2, 2024
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
10 changes: 8 additions & 2 deletions lib/rbi/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ def visit_constant_assign(node)
sig { override.params(node: Prism::DefNode).void }
def visit_def_node(node)
@last_node = node

# We need to collect the comments with `current_sigs_comments` _before_ visiting the parameters to make sure
# the method comments are properly associated with the sigs and not the parameters.
comments = current_sigs_comments + node_comments(node)
params = parse_params(node.parameters)

current_scope << Method.new(
node.name.to_s,
params: parse_params(node.parameters),
params: params,
sigs: current_sigs,
loc: node_loc(node),
comments: current_sigs_comments + node_comments(node),
comments: comments,
is_singleton: !!node.receiver,
)
@last_node = nil
Expand Down
2 changes: 1 addition & 1 deletion test/rbi/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ module A
# B comment
class B
# c comment
def c; end
def c(a); end

# d comment
attr_reader :a
Expand Down
Loading