Skip to content

Commit d84ada2

Browse files
committed
Fixed duplicate comments for modules from C
To workaround a C parser bug add_comment only allows a comment to be added once.
1 parent ecae6cb commit d84ada2

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

lib/rdoc/class_module.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RDoc::ClassModule < RDoc::Context
3131
##
3232
# Comment and the location it came from. Use #add_comment to add comments
3333

34-
attr_reader :comment_location
34+
attr_accessor :comment_location
3535

3636
attr_accessor :diagram # :nodoc:
3737

@@ -135,9 +135,7 @@ def add_comment comment, location
135135
normalize_comment comment
136136
end
137137

138-
return if @comment_location.any? do |(c, l)|
139-
c == comment and l == location
140-
end
138+
@comment_location.delete_if { |(_, l)| l == location }
141139

142140
@comment_location << [comment, location]
143141

lib/rdoc/store.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,16 @@ def find_c_enclosure variable
348348
@c_enclosure_classes.fetch variable do
349349
break unless name = @c_enclosure_names[variable]
350350

351-
mod = find_class_or_module(name) || load_class(name)
351+
mod = find_class_or_module name
352352

353-
break unless mod
353+
unless mod then
354+
loaded_mod = load_class_data name
355+
356+
file = loaded_mod.in_files.first
357+
file.store = self
358+
359+
mod = file.add_module RDoc::NormalModule, name
360+
end
354361

355362
@c_enclosure_classes[variable] = mod
356363
end
@@ -568,14 +575,10 @@ def load_cache
568575
end
569576

570577
##
571-
# Loads ri data for +klass_name+
578+
# Loads ri data for +klass_name+ and hooks it up to this store.
572579

573580
def load_class klass_name
574-
file = class_file klass_name
575-
576-
obj = open file, 'rb' do |io|
577-
Marshal.load io.read
578-
end
581+
obj = load_class_data klass_name
579582

580583
obj.store = self
581584

@@ -585,6 +588,17 @@ def load_class klass_name
585588
when RDoc::NormalModule then
586589
@modules_hash[klass_name] = obj
587590
end
591+
end
592+
593+
##
594+
# Loads ri data for +klass_name+
595+
596+
def load_class_data klass_name
597+
file = class_file klass_name
598+
599+
obj = open file, 'rb' do |io|
600+
Marshal.load io.read
601+
end
588602
rescue Errno::ENOENT => e
589603
error = MissingFileError.new(self, file, klass_name)
590604
error.set_backtrace e.backtrace

test/test_rdoc_class_module.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def test_add_comment_duplicate
4646

4747
cm = RDoc::ClassModule.new 'Klass'
4848
cm.add_comment '# comment 1', tl1
49-
cm.add_comment '# comment 1', tl1
49+
cm.add_comment '# comment 2', tl1
5050

51-
assert_equal [['comment 1', tl1]], cm.comment_location
51+
assert_equal [['comment 2', tl1]], cm.comment_location
5252
end
5353

5454
def test_add_comment_stopdoc

test/test_rdoc_store.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def setup
1818

1919
@klass = @top_level.add_class RDoc::NormalClass, 'Object'
2020
@klass.add_comment 'original', @top_level
21+
@klass.record_location @top_level
2122

2223
@cmeth = RDoc::AnyMethod.new nil, 'cmethod'
2324
@cmeth.singleton = true
@@ -264,7 +265,11 @@ def test_find_c_enclosure_from_cache
264265

265266
@s.c_enclosure_names['cObject'] = 'Object'
266267

267-
assert_equal @klass, @s.find_c_enclosure('cObject')
268+
klass = @s.find_c_enclosure('cObject')
269+
assert_equal @klass, klass
270+
271+
assert_empty klass.comment_location
272+
assert_equal @top_level, klass.parent
268273

269274
assert_includes @s.c_enclosure_classes, 'cObject'
270275
end

0 commit comments

Comments
 (0)