From bd6b2410b8d720028efc2d5faa72c2fc6be9beda Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Wed, 24 Jul 2024 14:36:54 -0400 Subject: [PATCH] Fix comments parsing for RBI::Method Signed-off-by: Alexandre Terrasa --- lib/rbi/parser.rb | 10 ++++++++-- test/rbi/parser_test.rb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/rbi/parser.rb b/lib/rbi/parser.rb index 1d311d40..1b9fc180 100644 --- a/lib/rbi/parser.rb +++ b/lib/rbi/parser.rb @@ -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 diff --git a/test/rbi/parser_test.rb b/test/rbi/parser_test.rb index a62674f0..f8368a20 100644 --- a/test/rbi/parser_test.rb +++ b/test/rbi/parser_test.rb @@ -720,7 +720,7 @@ module A # B comment class B # c comment - def c; end + def c(a); end # d comment attr_reader :a