@@ -244,6 +244,7 @@ def collect_first_comment
244244 comment = RDoc ::Encoding . change_encoding comment , @encoding if @encoding
245245 first_line = true
246246 first_comment_tk_kind = nil
247+ line_no = nil
247248
248249 tk = get_tk
249250
@@ -260,6 +261,7 @@ def collect_first_comment
260261 break if first_comment_tk_kind and not first_comment_tk_kind === tk [ :kind ]
261262 first_comment_tk_kind = tk [ :kind ]
262263
264+ line_no = tk [ :line_no ] if first_line
263265 first_line = false
264266 comment << comment_body
265267 tk = get_tk
@@ -273,7 +275,7 @@ def collect_first_comment
273275
274276 unget_tk tk
275277
276- new_comment comment
278+ new_comment comment , line_no
277279 end
278280
279281 ##
@@ -666,8 +668,9 @@ def make_message message
666668 ##
667669 # Creates a comment with the correct format
668670
669- def new_comment comment
671+ def new_comment comment , line_no = nil
670672 c = RDoc ::Comment . new comment , @top_level , :ruby
673+ c . line = line_no
671674 c . format = @markup
672675 c
673676 end
@@ -1058,13 +1061,14 @@ def parse_constant_body container, constant, is_array_or_hash # :nodoc:
10581061 def parse_comment container , tk , comment
10591062 return parse_comment_tomdoc container , tk , comment if @markup == 'tomdoc'
10601063 column = tk [ :char_no ]
1061- line_no = tk [ :line_no ]
1064+ line_no = comment . line . nil? ? tk [ :line_no ] : comment . line
10621065
10631066 comment . text = comment . text . sub ( /(^# +:?)(singleton-)(method:)/ , '\1\3' )
10641067 singleton = !!$~
10651068
10661069 co =
10671070 if ( comment . text = comment . text . sub ( /^# +:?method: *(\S *).*?\n /i , '' ) ) && !!$~ then
1071+ line_no += $`. count ( "\n " )
10681072 parse_comment_ghost container , comment . text , $1, column , line_no , comment
10691073 elsif ( comment . text = comment . text . sub ( /# +:?(attr(_reader|_writer|_accessor)?): *(\S *).*?\n /i , '' ) ) && !!$~ then
10701074 parse_comment_attr container , $1, $3, comment
@@ -1776,8 +1780,10 @@ def parse_statements(container, single = NORMAL, current_method = nil,
17761780 comment = RDoc ::Encoding . change_encoding comment , @encoding if @encoding
17771781 end
17781782
1783+ line_no = nil
17791784 while tk and ( :on_comment == tk [ :kind ] or :on_embdoc == tk [ :kind ] ) do
17801785 comment_body = retrieve_comment_body ( tk )
1786+ line_no = tk [ :line_no ] if comment . empty?
17811787 comment += comment_body
17821788 comment << "\n " unless comment_body =~ /\n \z /
17831789
@@ -1787,7 +1793,7 @@ def parse_statements(container, single = NORMAL, current_method = nil,
17871793 tk = get_tk
17881794 end
17891795
1790- comment = new_comment comment
1796+ comment = new_comment comment , line_no
17911797
17921798 unless comment . empty? then
17931799 look_for_directives_in container , comment
0 commit comments