lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.94k stars 397 forks source link

Documented classes missing from generated class_list.html but present in generated alphabetical index. #1518

Open mcorino opened 10 months ago

mcorino commented 10 months ago

I noticed today that several (17) classes (of a total of 749) were missing from the generated class_list.html while they were present in the generated alphabetical index as well as having a proper class .html generated which was also properly crosslinked. One class is my 'Wx::App' where 'Wx' is the topmost namespace of the library.

Looking through the code and doing some debugging I found that at the point of the classlist method in 'templates/default/fulldoc/html/setup.rb' the object instance from Registry.root representing the topmost 'Wx' module did not have an instance for the 'Wx::App' class in its #children list. That instance was however present when looked up with Registry.at('Wx::App') and the #namespace instance object of that object DID have an instance for 'Wx::App' in its #children list. Comparing the object_id-s of the 'Wx' instance included in Registry.root and the #namespace instance showed these were different objects and both were NOT proxies but fully resolved objects which I had not expected to be the case.

The debug output from yardoc does not show any errors or other noticable messages.

I have a workaround by loading a template customization for 'templates/default/fulldoc/html/setup.rb' which contains this code:

# frozen_string_literal: true

def init
  # It seems YARD messes things up so that a number of classes are not properly
  # registered in their enclosing namespaces.
  # This hack makes sure that if that is the case we fix that here.
  all_classes = Registry.all(:class)
  all_classes.each do |c|
    if (ns = c.namespace)
      unless ns.children.any? { |nsc| nsc.path == c.path }
        ns.children << c # class missing from child list of enclosing namespace -> add here
      end
    end
    if (ns = Registry[c.namespace.path])
      unless ns.children.any? { |nsc| nsc.path == c.path }
        ns.children << c # class missing from child list of enclosing namespace -> add here
      end
    end
  end
  super
end

I don't think the first if ... end block is really necessary but the second definitely is.

This currently solves the problem for me but I do not much like having to maintain this horrible hack.

Does anyone have an idea what is causing this problem?

Steps to reproduce

I cannot reproduce with a minimal sample. Seems to be somehow related to larger, more complex documenting setups. The project I am generating for is https://github.com/mcorino/wxRuby3.

Actual Output

Documented classes missing from generated class_list.html

Expected Output

A generated class_list.html including all documented classes.

Environment details:

I have read the Contributing Guide.