ruby / rdoc

RDoc produces HTML and online documentation for Ruby projects.
https://ruby.github.io/rdoc/
Other
841 stars 438 forks source link

Missing constants possibly related to mixed c/rb and nested classes #399

Open dsvensson opened 8 years ago

dsvensson commented 8 years ago

Minimal test case to reproduce:

Create two files,

async.rb:

class Xmms::Collection::Async
end

collection.c:

void
Init_Collection()
{
    mXmms = rb_define_module("Xmms");

    cColl = rb_define_class_under(mXmms, "Collection", rb_cObject);

    /* Document-const: Xmms::Collection::NS_ALL
     *
     * I am documentation */
    rb_define_const(cColl, "NS_ALL", rb_str_new2(XMMS_COLLECTION_NS_ALL));
}

Build with: rdoc async.rb collection.c

And notice the lack of the NS_ALL constant.

drbrain commented 8 years ago

Fixed!

dsvensson commented 8 years ago

Any plans for a new release any time soon?

zzak commented 8 years ago

I'll make a bug-fix release in the next day or two, thank you!

dsvensson commented 8 years ago

Should this also cover refering to constants that were previously not emitted in the documentation due to this bug?

Here I access the constant via irb:

$ irb
irb(main):001:0> require "xmmsclient"
=> true
irb(main):002:0> Xmms::Collection::NS_ALL
=> "*"

If I however type Xmms::Collection::NS_ALL, defined in rb_collection.c, in the comment for a method in the file that declares Xmms::Client, rb_xmmsclient.c, I will not get a link for that constant. Nor will I if I type "Xmms::Collection::NS_ALL" in the comment of any method defined in the same file as NS_ALL. If I instead type "NS_ALL" in a comment of a method defined in the same file as NS_ALL, I will get a link, so maybe Xmms::Collection::NS_ALL is an invalid syntax in rdoc when it comes to constants? Anyways.. if I go back to refering to simply "NS_ALL" in another file rather than the same - I will not get any link.

The files in question for the whole of this issue are found at: https://github.com/dsvensson/xmms2-devel/tree/master/src/clients/lib/ruby

zzak commented 8 years ago

@dsvensson Does it work (from another file than this constant is defined) if you use the entire name like Xmms::Collection::NS_ALL? For example, only "NS_ALL" isn't linking in another file?

dsvensson commented 8 years ago

No. Full namespace+constant doesn't work in any file.

zzak commented 8 years ago

Ugh :(

@dsvensson are you testing with master?

dsvensson commented 8 years ago

Not really. I tried "rake package" and installd the resulting gem file (name oddly contained "borked" or somesuch). "which rdoc" points to the binary under my user's home dir. When running rdoc it seems as if it still uses parts of my system wide version so I removed the gem again and applied the patch for this issue on the system wide one (Fedora 23). This makes the constant emitting work and my docs have all the methods/constant that should be there. The linking is however broken. I run "rdoc src/clients/lib/ruby/*.{c,rb}" on the repo mentioned above and under Xmms::Client there is a doc reference to Xmms::Collection::NS_ALL that will not become a link. Does that work for you? What am I missing with my gem installation of rdoc, it would obviously be better if I used master properly.

zzak commented 8 years ago

Hmm, you should be able to install the gem package and Ruby will pick the newest version.

You could try patching the install you have, but that seems problematic.

If you have a smaller reproduce, that would help! Can you reproduce it with the code you originally submitted in the issue description?

dsvensson commented 8 years ago

Werid.. pulled again and now I got a rdoc-4.2.3.gem instead of rdoc-0.borked.gem, and rdoc --version now prints the correct version - 4.2.3, and after reinstalling my system wide rdoc such that it is no longer patched, the local user gem with rdoc from master now produces the correct output, except for the missing link when using Xmms::Collection::NS_ALL (defined in rb_collection.c) in the comment of c_coll_list function in rb_xmmsclient.c in the repository linked above. I'll have a look if the const links are broken in the example you talk about now.

dsvensson commented 8 years ago

Yep, added a client.c together with the two files mentioned in the original description, it's broken.

/*
 * call-seq:
 * xc.coll_list([ns]) -> result
 *
 * Trying all permutations here that I can imagine, just to be sure, nothing works. 
 * Xmms::Collection::NS_ALL NS_ALL ::NS_ALL.
 */
static VALUE
c_coll_list (int argc, VALUE *argv, VALUE self)
{
    return NULL;
}

void
Init_Client()
{
    mXmms = rb_define_module("Xmms");
    c = rb_define_class_under(mXmms, "Client", rb_cObject);
    rb_define_method (c, "coll_list", c_coll_list, -1);
}
zzak commented 8 years ago

So after some poking, I was able to reproduce this only when trying to refer to the constant from another class. Within a different file is ok, as long as it's in the same class.

Here are the files I used to reproduce:

# ok.rb
module Zomg
  class Wtf
    # Check out Zomg::Wtf::BBQ
    # or BBQ
    # or maybe even ::BBQ
    # it should be there, i promise!
    def rly
      puts "i'm a method"
    end
  end
end
# rly.rb
class Rly
  # this is another method
  # perhaps we can reference Zomg::Wtf::BBQ from here?
  # well
  # how about at least the class? Zomg::Wtf
  def asdf
  end
end
// zomg.c
void
Init_Zomg()
{
    zomg = rb_define_module("Zomg");
    wtf = rb_define_class_under(zomg, "Wtf", rb_cObject);

    /* Document-const: Zomg::Wtf::BBQ
     *
     * zomgzomgozmg */
    rb_define_const(wtf, "BBQ", Qnil);
}
zzak commented 8 years ago

After some debugging, I was able to fix a bug when using the full constant name within the same class/context wasn't linking.

I'm, however, stumped as to how to fix this for another class not in the current context.. /cc @drbrain