Skip to content

Remove offset from CodeObject #445

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 5 commits into from
Apr 2, 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
7 changes: 0 additions & 7 deletions lib/rdoc/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ class RDoc::CodeObject

attr_reader :metadata

##
# Offset in #file where this CodeObject was defined
#--
# TODO character or byte?

attr_accessor :offset

##
# Sets the parent CodeObject

Expand Down
2 changes: 0 additions & 2 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
tk.set_text body
meth_obj.add_token tk
meth_obj.comment = comment
meth_obj.offset = offset
meth_obj.line = file_content[0, offset].count("\n") + 1

body
Expand All @@ -689,7 +688,6 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
tk.set_text body
meth_obj.add_token tk
meth_obj.comment = comment
meth_obj.offset = offset
meth_obj.line = file_content[0, offset].count("\n") + 1

body
Expand Down
23 changes: 3 additions & 20 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ def new_comment comment
# +comment+.

def parse_attr(context, single, tk, comment)
offset = tk.seek
line_no = tk.line_no

args = parse_symbol_arg 1
Expand All @@ -606,7 +605,6 @@ def parse_attr(context, single, tk, comment)
end

att = create_attr context, single, name, rw, comment
att.offset = offset
att.line = line_no

read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
Expand All @@ -620,7 +618,6 @@ def parse_attr(context, single, tk, comment)
# comment for each to +comment+.

def parse_attr_accessor(context, single, tk, comment)
offset = tk.seek
line_no = tk.line_no

args = parse_symbol_arg
Expand All @@ -642,7 +639,6 @@ def parse_attr_accessor(context, single, tk, comment)

for name in args
att = create_attr context, single, name, rw, comment
att.offset = offset
att.line = line_no
end
end
Expand All @@ -651,7 +647,6 @@ def parse_attr_accessor(context, single, tk, comment)
# Parses an +alias+ in +context+ with +comment+

def parse_alias(context, single, tk, comment)
offset = tk.seek
line_no = tk.line_no

skip_tkspace
Expand Down Expand Up @@ -680,7 +675,6 @@ def parse_alias(context, single, tk, comment)
al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
single == SINGLE)
record_location al
al.offset = offset
al.line = line_no

read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
Expand Down Expand Up @@ -733,7 +727,6 @@ def parse_call_parameters(tk)
# Parses a class in +context+ with +comment+

def parse_class container, single, tk, comment
offset = tk.seek
line_no = tk.line_no

declaration_context = container
Expand All @@ -748,7 +741,7 @@ def parse_class container, single, tk, comment
case name = get_class_specification
when 'self', container.name
parse_statements container, SINGLE
return # don't update offset or line
return # don't update line
else
parse_class_singleton container, name, comment
end
Expand All @@ -757,7 +750,6 @@ def parse_class container, single, tk, comment
return
end

cls.offset = offset
cls.line = line_no

cls
Expand Down Expand Up @@ -845,7 +837,6 @@ def parse_class_singleton container, name, comment # :nodoc:
# true, no found constants will be added to RDoc.

def parse_constant container, tk, comment, ignore_constants = false
offset = tk.seek
line_no = tk.line_no

name = tk.name
Expand Down Expand Up @@ -885,7 +876,6 @@ def parse_constant container, tk, comment, ignore_constants = false

value.replace body
record_location con
con.offset = offset
con.line = line_no
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS

Expand Down Expand Up @@ -950,7 +940,6 @@ def parse_constant_body container, constant # :nodoc:
def parse_comment container, tk, comment
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
column = tk.char_no
offset = tk.seek
line_no = tk.line_no

text = comment.text
Expand All @@ -966,7 +955,6 @@ def parse_comment container, tk, comment

if co then
co.singleton = singleton
co.offset = offset
co.line = line_no
end

Expand Down Expand Up @@ -1031,19 +1019,18 @@ def parse_comment_ghost container, text, name, column, line_no, # :nodoc:

def parse_comment_tomdoc container, tk, comment
return unless signature = RDoc::TomDoc.signature(comment)
offset = tk.seek
column = tk.char_no
line_no = tk.line_no

name, = signature.split %r%[ \(]%, 2

meth = RDoc::GhostMethod.new get_tkread, name
record_location meth
meth.offset = offset
meth.line = line_no

meth.start_collecting_tokens
indent = TkSPACE.new 0, 1, 1
indent.set_text " " * offset
indent.set_text " " * column

position_comment = TkCOMMENT.new 0, line_no, 1
position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
Expand Down Expand Up @@ -1183,7 +1170,6 @@ def parse_meta_attr(context, single, tk, comment)

def parse_meta_method(container, single, tk, comment)
column = tk.char_no
offset = tk.seek
line_no = tk.line_no

start_collecting_tokens
Expand All @@ -1200,7 +1186,6 @@ def parse_meta_method(container, single, tk, comment)

meth = RDoc::MetaMethod.new get_tkread, name
record_location meth
meth.offset = offset
meth.line = line_no
meth.singleton = singleton

Expand Down Expand Up @@ -1291,7 +1276,6 @@ def parse_method(container, single, tk, comment)
added_container = false
name = nil
column = tk.char_no
offset = tk.seek
line_no = tk.line_no

start_collecting_tokens
Expand All @@ -1309,7 +1293,6 @@ def parse_method(container, single, tk, comment)
meth.singleton = single == SINGLE ? true : singleton

record_location meth
meth.offset = offset
meth.line = line_no

meth.start_collecting_tokens
Expand Down
6 changes: 0 additions & 6 deletions test/test_rdoc_code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ def test_metadata
assert_equal 'not_rdoc', @co.metadata['markup']
end

def test_offset
@c1_m.offset = 5

assert_equal 5, @c1_m.offset
end

def test_options
assert_kind_of RDoc::Options, @co.options

Expand Down
3 changes: 0 additions & 3 deletions test/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,6 @@ def test_find_body_define
assert_equal 'my_method', other_function.name
assert_equal 'a comment for rb_other_function', other_function.comment.text
assert_equal '()', other_function.params
assert_equal 118, other_function.offset
assert_equal 8, other_function.line

code = other_function.token_stream.first.text
Expand Down Expand Up @@ -1173,7 +1172,6 @@ def test_find_body_define_comment
assert_equal 'my_method', other_function.name
assert_equal 'a comment for other_function', other_function.comment.text
assert_equal '()', other_function.params
assert_equal 39, other_function.offset
assert_equal 4, other_function.line

code = other_function.token_stream.first.text
Expand Down Expand Up @@ -1402,7 +1400,6 @@ def test_handle_method_args_minus_1

assert_equal 'm', m.name
assert_equal @top_level, m.file
assert_equal 115, m.offset
assert_equal 7, m.line

assert_equal '(p1)', m.params
Expand Down
12 changes: 0 additions & 12 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def test_parse_alias
assert_equal klass, alas.parent
assert_equal 'comment', alas.comment
assert_equal @top_level, alas.file
assert_equal 0, alas.offset
assert_equal 1, alas.line
end

Expand Down Expand Up @@ -365,7 +364,6 @@ def test_parse_attr
assert_equal 'foo', foo.name
assert_equal 'my attr', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line
end

Expand Down Expand Up @@ -404,7 +402,6 @@ def test_parse_attr_accessor
assert_equal 'RW', foo.rw
assert_equal 'my attr', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line

bar = klass.attributes.last
Expand Down Expand Up @@ -617,7 +614,6 @@ def test_parse_class
assert_equal 'Foo', foo.full_name
assert_equal 'my class', foo.comment.text
assert_equal [@top_level], foo.in_files
assert_equal 0, foo.offset
assert_equal 1, foo.line
end

Expand All @@ -637,7 +633,6 @@ class << self

c = @top_level.classes.first
assert_equal 'C', c.full_name
assert_equal 0, c.offset
assert_equal 1, c.line
end

Expand Down Expand Up @@ -727,7 +722,6 @@ def test_parse_class_nodoc
assert_equal 'Foo', foo.full_name
assert_empty foo.comment
assert_equal [@top_level], foo.in_files
assert_equal 0, foo.offset
assert_equal 1, foo.line
end

Expand Down Expand Up @@ -920,7 +914,6 @@ def foo; end
assert_equal %w[A::B A::d], modules.map { |c| c.full_name }

b = modules.first
assert_equal 10, b.offset
assert_equal 2, b.line

# make sure method/alias was not added to enclosing class/module
Expand Down Expand Up @@ -1083,7 +1076,6 @@ def test_parse_comment_attr
assert_equal 'RW', foo.rw
assert_equal 'my attr', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line

assert_equal nil, foo.viewer
Expand Down Expand Up @@ -1147,7 +1139,6 @@ def test_parse_comment_method
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line

assert_equal [], foo.aliases
Expand Down Expand Up @@ -1223,7 +1214,6 @@ def test_parse_constant

assert_equal 'A', foo.name
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line
end

Expand Down Expand Up @@ -1389,7 +1379,6 @@ def test_parse_meta_method
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line

assert_equal [], foo.aliases
Expand Down Expand Up @@ -1587,7 +1576,6 @@ def test_parse_method
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment.text
assert_equal @top_level, foo.file
assert_equal 0, foo.offset
assert_equal 1, foo.line

assert_equal [], foo.aliases
Expand Down