Skip to content

Commit c1e9e03

Browse files
committed
Set line and offset correctly
1 parent 0d16de3 commit c1e9e03

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def make_message message
452452
# +comment+.
453453

454454
def parse_attr(context, single, tk, comment)
455-
column = tk.char_no
455+
offset = tk.seek
456456
line_no = tk.line_no
457457

458458
args = parse_symbol_arg 1
@@ -470,7 +470,7 @@ def parse_attr(context, single, tk, comment)
470470

471471
att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
472472
att.record_location @top_level
473-
att.offset = column
473+
att.offset = offset
474474
att.line = line_no
475475

476476
read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
@@ -488,7 +488,7 @@ def parse_attr(context, single, tk, comment)
488488
# comment for each to +comment+.
489489

490490
def parse_attr_accessor(context, single, tk, comment)
491-
column = tk.char_no
491+
offset = tk.seek
492492
line_no = tk.line_no
493493

494494
args = parse_symbol_arg
@@ -509,7 +509,7 @@ def parse_attr_accessor(context, single, tk, comment)
509509
for name in args
510510
att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
511511
att.record_location @top_level
512-
att.offset = column
512+
att.offset = offset
513513
att.line = line_no
514514

515515
context.add_attribute att
@@ -521,7 +521,7 @@ def parse_attr_accessor(context, single, tk, comment)
521521
# Parses an +alias+ in +context+ with +comment+
522522

523523
def parse_alias(context, single, tk, comment)
524-
column = tk.char_no
524+
offset = tk.seek
525525
line_no = tk.line_no
526526

527527
skip_tkspace
@@ -550,7 +550,7 @@ def parse_alias(context, single, tk, comment)
550550
al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
551551
single == SINGLE)
552552
al.record_location @top_level
553-
al.offset = column
553+
al.offset = offset
554554
al.line = line_no
555555

556556
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
@@ -604,7 +604,7 @@ def parse_call_parameters(tk)
604604
# Parses a class in +context+ with +comment+
605605

606606
def parse_class(container, single, tk, comment)
607-
column = tk.char_no
607+
offset = tk.seek
608608
line_no = tk.line_no
609609

610610
declaration_context = container
@@ -627,7 +627,7 @@ def parse_class(container, single, tk, comment)
627627

628628
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
629629
cls.record_location @top_level
630-
cls.offset = column
630+
cls.offset = offset
631631
cls.line = line_no
632632

633633
cls.comment = comment if cls.document_self
@@ -646,7 +646,7 @@ def parse_class(container, single, tk, comment)
646646
unless other then
647647
other = container.add_module RDoc::NormalModule, name
648648
other.record_location @top_level
649-
other.offset = column
649+
other.offset = offset
650650
other.line = line_no
651651

652652
other.comment = comment
@@ -675,7 +675,7 @@ def parse_class(container, single, tk, comment)
675675
# Parses a constant in +context+ with +comment+
676676

677677
def parse_constant(container, tk, comment)
678-
column = tk.char_no
678+
offset = tk.seek
679679
line_no = tk.line_no
680680

681681
name = tk.name
@@ -750,7 +750,7 @@ def parse_constant(container, tk, comment)
750750

751751
con = RDoc::Constant.new name, res, comment
752752
con.record_location @top_level
753-
con.offset = column
753+
con.offset = offset
754754
con.line = line_no
755755
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
756756

@@ -764,8 +764,9 @@ def parse_constant(container, tk, comment)
764764
# :method: or :attr: directives in +comment+.
765765

766766
def parse_comment(container, tk, comment)
767-
line_no = tk.line_no
768767
column = tk.char_no
768+
offset = tk.seek
769+
line_no = tk.line_no
769770

770771
singleton = !!comment.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
771772

@@ -776,7 +777,7 @@ def parse_comment(container, tk, comment)
776777
meth = RDoc::GhostMethod.new get_tkread, name
777778
meth.record_location @top_level
778779
meth.singleton = singleton
779-
meth.offset = column
780+
meth.offset = offset
780781
meth.line = line_no
781782

782783
meth.start_collecting_tokens
@@ -810,7 +811,7 @@ def parse_comment(container, tk, comment)
810811
# TODO authorize 'singleton-attr...'?
811812
att = RDoc::Attr.new get_tkread, name, rw, comment
812813
att.record_location @top_level
813-
att.offset = column
814+
att.offset = offset
814815
att.line = line_no
815816

816817
container.add_attribute att
@@ -906,8 +907,9 @@ def parse_meta_attr(context, single, tk, comment)
906907
# Parses a meta-programmed method
907908

908909
def parse_meta_method(container, single, tk, comment)
909-
line_no = tk.line_no
910910
column = tk.char_no
911+
offset = tk.seek
912+
line_no = tk.line_no
911913

912914
start_collecting_tokens
913915
add_token tk
@@ -939,7 +941,7 @@ def parse_meta_method(container, single, tk, comment)
939941

940942
meth = RDoc::MetaMethod.new get_tkread, name
941943
meth.record_location @top_level
942-
meth.offset = column
944+
meth.offset = offset
943945
meth.line = line_no
944946
meth.singleton = singleton
945947

@@ -993,8 +995,9 @@ def parse_method(container, single, tk, comment)
993995
added_container = nil
994996
meth = nil
995997
name = nil
996-
line_no = tk.line_no
997998
column = tk.char_no
999+
offset = tk.seek
1000+
line_no = tk.line_no
9981001

9991002
start_collecting_tokens
10001003
add_token tk
@@ -1086,7 +1089,7 @@ def parse_method(container, single, tk, comment)
10861089
end
10871090

10881091
meth.record_location @top_level
1089-
meth.offset = column
1092+
meth.offset = offset
10901093
meth.line = line_no
10911094

10921095
meth.start_collecting_tokens

test/test_rdoc_parser_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def foo; end
801801
assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name }
802802

803803
b = RDoc::TopLevel.modules.first
804-
assert_equal 2, b.offset # HACK should be 10
804+
assert_equal 10, b.offset
805805
assert_equal 2, b.line
806806

807807
# make sure method/alias was not added to enclosing class/module

0 commit comments

Comments
 (0)