Fix ghost method line no
This commit is contained in:
parent
f9debf3437
commit
2d0a1a1869
@ -23,6 +23,11 @@ class RDoc::Comment
|
|||||||
|
|
||||||
attr_accessor :location
|
attr_accessor :location
|
||||||
|
|
||||||
|
##
|
||||||
|
# Line where this Comment was written
|
||||||
|
|
||||||
|
attr_accessor :line
|
||||||
|
|
||||||
##
|
##
|
||||||
# For duck-typing when merging classes at load time
|
# For duck-typing when merging classes at load time
|
||||||
|
|
||||||
|
@ -244,6 +244,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
||||||
first_line = true
|
first_line = true
|
||||||
first_comment_tk_kind = nil
|
first_comment_tk_kind = nil
|
||||||
|
line_no = nil
|
||||||
|
|
||||||
tk = get_tk
|
tk = get_tk
|
||||||
|
|
||||||
@ -260,6 +261,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
break if first_comment_tk_kind and not first_comment_tk_kind === tk[:kind]
|
break if first_comment_tk_kind and not first_comment_tk_kind === tk[:kind]
|
||||||
first_comment_tk_kind = tk[:kind]
|
first_comment_tk_kind = tk[:kind]
|
||||||
|
|
||||||
|
line_no = tk[:line_no] if first_line
|
||||||
first_line = false
|
first_line = false
|
||||||
comment << comment_body
|
comment << comment_body
|
||||||
tk = get_tk
|
tk = get_tk
|
||||||
@ -273,7 +275,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
|
|
||||||
unget_tk tk
|
unget_tk tk
|
||||||
|
|
||||||
new_comment comment
|
new_comment comment, line_no
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -666,8 +668,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
##
|
##
|
||||||
# Creates a comment with the correct format
|
# Creates a comment with the correct format
|
||||||
|
|
||||||
def new_comment comment
|
def new_comment comment, line_no = nil
|
||||||
c = RDoc::Comment.new comment, @top_level, :ruby
|
c = RDoc::Comment.new comment, @top_level, :ruby
|
||||||
|
c.line = line_no
|
||||||
c.format = @markup
|
c.format = @markup
|
||||||
c
|
c
|
||||||
end
|
end
|
||||||
@ -1058,13 +1061,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
def parse_comment container, tk, comment
|
def parse_comment container, tk, comment
|
||||||
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
|
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
|
||||||
column = tk[:char_no]
|
column = tk[:char_no]
|
||||||
line_no = tk[:line_no]
|
line_no = comment.line.nil? ? tk[:line_no] : comment.line
|
||||||
|
|
||||||
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
|
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
|
||||||
singleton = !!$~
|
singleton = !!$~
|
||||||
|
|
||||||
co =
|
co =
|
||||||
if (comment.text = comment.text.sub(/^# +:?method: *(\S*).*?\n/i, '')) && !!$~ then
|
if (comment.text = comment.text.sub(/^# +:?method: *(\S*).*?\n/i, '')) && !!$~ then
|
||||||
|
line_no += $`.count("\n")
|
||||||
parse_comment_ghost container, comment.text, $1, column, line_no, comment
|
parse_comment_ghost container, comment.text, $1, column, line_no, comment
|
||||||
elsif (comment.text = comment.text.sub(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '')) && !!$~ then
|
elsif (comment.text = comment.text.sub(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '')) && !!$~ then
|
||||||
parse_comment_attr container, $1, $3, comment
|
parse_comment_attr container, $1, $3, comment
|
||||||
@ -1776,8 +1780,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
line_no = nil
|
||||||
while tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) do
|
while tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) do
|
||||||
comment_body = retrieve_comment_body(tk)
|
comment_body = retrieve_comment_body(tk)
|
||||||
|
line_no = tk[:line_no] if comment.empty?
|
||||||
comment += comment_body
|
comment += comment_body
|
||||||
comment << "\n" unless comment_body =~ /\n\z/
|
comment << "\n" unless comment_body =~ /\n\z/
|
||||||
|
|
||||||
@ -1787,7 +1793,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
tk = get_tk
|
tk = get_tk
|
||||||
end
|
end
|
||||||
|
|
||||||
comment = new_comment comment
|
comment = new_comment comment, line_no
|
||||||
|
|
||||||
unless comment.empty? then
|
unless comment.empty? then
|
||||||
look_for_directives_in container, comment
|
look_for_directives_in container, comment
|
||||||
|
@ -776,6 +776,7 @@ end
|
|||||||
|
|
||||||
blah = foo.method_list.first
|
blah = foo.method_list.first
|
||||||
assert_equal 'Foo#blah', blah.full_name
|
assert_equal 'Foo#blah', blah.full_name
|
||||||
|
assert_equal 3, blah.line
|
||||||
assert_equal @top_level, blah.file
|
assert_equal @top_level, blah.file
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -825,6 +826,7 @@ end
|
|||||||
blah = foo.method_list.first
|
blah = foo.method_list.first
|
||||||
assert_equal 'Foo#yields', blah.full_name
|
assert_equal 'Foo#yields', blah.full_name
|
||||||
assert_equal 'yields(name)', blah.call_seq
|
assert_equal 'yields(name)', blah.call_seq
|
||||||
|
assert_equal 3, blah.line
|
||||||
assert_equal @top_level, blah.file
|
assert_equal @top_level, blah.file
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1323,7 +1325,7 @@ EOF
|
|||||||
assert_equal 'foo', foo.name
|
assert_equal 'foo', foo.name
|
||||||
assert_equal 'my method', foo.comment.text
|
assert_equal 'my method', foo.comment.text
|
||||||
assert_equal @top_level, foo.file
|
assert_equal @top_level, foo.file
|
||||||
assert_equal 1, foo.line
|
assert_equal 2, foo.line
|
||||||
|
|
||||||
assert_equal [], foo.aliases
|
assert_equal [], foo.aliases
|
||||||
assert_nil foo.block_params
|
assert_nil foo.block_params
|
||||||
@ -1344,8 +1346,8 @@ EOF
|
|||||||
|
|
||||||
stream = [
|
stream = [
|
||||||
{
|
{
|
||||||
:line_no => 1, :char_no => 1, :kind => :on_comment,
|
:line_no => 2, :char_no => 1, :kind => :on_comment,
|
||||||
:text => "# File #{@top_level.relative_name}, line 1"
|
:text => "# File #{@top_level.relative_name}, line 2"
|
||||||
},
|
},
|
||||||
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
|
{ :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" },
|
||||||
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' }
|
{ :line_no => 1, :char_no => 1, :kind => :on_sp, :text => '' }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user