@@ -244,6 +244,7 @@ def collect_first_comment
244
244
comment = RDoc ::Encoding . change_encoding comment , @encoding if @encoding
245
245
first_line = true
246
246
first_comment_tk_kind = nil
247
+ line_no = nil
247
248
248
249
tk = get_tk
249
250
@@ -260,6 +261,7 @@ def collect_first_comment
260
261
break if first_comment_tk_kind and not first_comment_tk_kind === tk [ :kind ]
261
262
first_comment_tk_kind = tk [ :kind ]
262
263
264
+ line_no = tk [ :line_no ] if first_line
263
265
first_line = false
264
266
comment << comment_body
265
267
tk = get_tk
@@ -273,7 +275,7 @@ def collect_first_comment
273
275
274
276
unget_tk tk
275
277
276
- new_comment comment
278
+ new_comment comment , line_no
277
279
end
278
280
279
281
##
@@ -666,8 +668,9 @@ def make_message message
666
668
##
667
669
# Creates a comment with the correct format
668
670
669
- def new_comment comment
671
+ def new_comment comment , line_no = nil
670
672
c = RDoc ::Comment . new comment , @top_level , :ruby
673
+ c . line = line_no
671
674
c . format = @markup
672
675
c
673
676
end
@@ -1058,13 +1061,14 @@ def parse_constant_body container, constant, is_array_or_hash # :nodoc:
1058
1061
def parse_comment container , tk , comment
1059
1062
return parse_comment_tomdoc container , tk , comment if @markup == 'tomdoc'
1060
1063
column = tk [ :char_no ]
1061
- line_no = tk [ :line_no ]
1064
+ line_no = comment . line . nil? ? tk [ :line_no ] : comment . line
1062
1065
1063
1066
comment . text = comment . text . sub ( /(^# +:?)(singleton-)(method:)/ , '\1\3' )
1064
1067
singleton = !!$~
1065
1068
1066
1069
co =
1067
1070
if ( comment . text = comment . text . sub ( /^# +:?method: *(\S *).*?\n /i , '' ) ) && !!$~ then
1071
+ line_no += $`. count ( "\n " )
1068
1072
parse_comment_ghost container , comment . text , $1, column , line_no , comment
1069
1073
elsif ( comment . text = comment . text . sub ( /# +:?(attr(_reader|_writer|_accessor)?): *(\S *).*?\n /i , '' ) ) && !!$~ then
1070
1074
parse_comment_attr container , $1, $3, comment
@@ -1776,8 +1780,10 @@ def parse_statements(container, single = NORMAL, current_method = nil,
1776
1780
comment = RDoc ::Encoding . change_encoding comment , @encoding if @encoding
1777
1781
end
1778
1782
1783
+ line_no = nil
1779
1784
while tk and ( :on_comment == tk [ :kind ] or :on_embdoc == tk [ :kind ] ) do
1780
1785
comment_body = retrieve_comment_body ( tk )
1786
+ line_no = tk [ :line_no ] if comment . empty?
1781
1787
comment += comment_body
1782
1788
comment << "\n " unless comment_body =~ /\n \z /
1783
1789
@@ -1787,7 +1793,7 @@ def parse_statements(container, single = NORMAL, current_method = nil,
1787
1793
tk = get_tk
1788
1794
end
1789
1795
1790
- comment = new_comment comment
1796
+ comment = new_comment comment , line_no
1791
1797
1792
1798
unless comment . empty? then
1793
1799
look_for_directives_in container , comment
0 commit comments