Skip to content

Support :args: directive before method #541

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

Merged
merged 1 commit into from
Oct 24, 2017
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
2 changes: 1 addition & 1 deletion lib/rdoc/markup/pre_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def handle_directive prefix, directive, param, code_object = nil,

case directive
when 'arg', 'args' then
return "#{prefix}:#{directive}: #{param}\n" unless code_object
return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(RDoc::AnyMethod)

code_object.params = param

Expand Down
9 changes: 6 additions & 3 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,15 @@ def suppress_parents container, ancestor # :nodoc:
#
# This routine modifies its +comment+ parameter.

def look_for_directives_in context, comment
@preprocess.handle comment, context do |directive, param|
def look_for_directives_in container, comment
@preprocess.handle comment, container do |directive, param|
case directive
when 'method', 'singleton-method',
'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
false # handled elsewhere
when 'section' then
context.set_current_section param, comment.dup
break unless container.kind_of?(RDoc::Context)
container.set_current_section param, comment.dup
comment.text = ''
break
end
Expand Down Expand Up @@ -1290,6 +1291,7 @@ def parse_meta_method_params container, single, meth, tk, comment # :nodoc:
token_listener meth do
meth.params = ''

look_for_directives_in meth, comment
comment.normalize
comment.extract_call_seq meth

Expand Down Expand Up @@ -1336,6 +1338,7 @@ def parse_method(container, single, tk, comment)
return unless name

meth = RDoc::AnyMethod.new get_tkread, name
look_for_directives_in meth, comment
meth.singleton = single == SINGLE ? true : singleton

record_location meth
Expand Down
22 changes: 22 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,28 @@ def test_parse_redefinable_methods
end
end

def test_parse_method_with_args_directive
util_parser <<-RUBY
class C
def meth_with_args_after # :args: a, b, c
end

##
# :args: d, e, f
def meth_with_args_before
end
RUBY

@parser.scan

c = @store.find_class_named 'C'

assert_equal 'C#meth_with_args_after', c.method_list[0].full_name
assert_equal 'a, b, c', c.method_list[0].params
assert_equal 'C#meth_with_args_before', c.method_list[1].full_name
assert_equal 'd, e, f', c.method_list[1].params
end

def test_parse_method_bracket
util_parser <<-RUBY
class C
Expand Down