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
Issue #5759 -- inherit documentation #6981
Issue #5759 -- inherit documentation #6981
Conversation
Added option to inherit documentation from a superclass's methods or class methods
Added option to inherit documentation from a superclass's macro definition
Added option to inherit documentation from a superclass's constant definition
end | ||
|
||
def inherit_docs?(str : String) | ||
str.starts_with?(":inherit:") || str.starts_with?("inherit") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just :inherit:
, ditto all below (btw could it get more DRY?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I'd change it to str == ":inherit:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you want to inherit docs and add some specific doc afterward?
like:
# :inherit:
# Some specific doc
def foo
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bew I thought about but it's IMO better to add it in another PR since it'd be beneficial for :ditto:
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you want to inherit docs and add some specific doc afterward?
I'm not sure that makes sense with :inherit:
or :ditto:
. What would it mean? Just append everything following the keyword? Or ignore it as internal comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say append everything, for internal comments you'd use :nodoc:
or put the doc inside the method (as a workaround)
@@ -20,7 +20,15 @@ class Crystal::Doc::Method | |||
end | |||
|
|||
def doc | |||
@def.doc | |||
if inherit_docs? @def.doc | |||
(@type.superclass.lookup_method(name) || @type.superclass.lookup_class_method(name)).doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use @type.ancestors
which gives you the full type hierarchy (including modules) because @type.superclass
just gives you the superclass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also wrong because it just checks for the name, ignoring argument names and types.
This is good! Though I'm thinking it's probably better to have an |
@asterite aren't they orthogonal? |
@RX14 If you override a method and you don't specify docs, I think it makes sense to inherit the docs. |
@asterite https://github.com/GrottoPress/crystal-annotation has a simple
Wouldn't it make more sense to don't even merge But in general, I like this either way. |
@asterite inherit allows composing documentation by adding |
@RX14 not with the current implementation from this PR, but as I said earlier in #6981 (comment) it's sensible to do it in a followup PR. |
@RX14 Ah, that makes sense. Well, in any case, the implementation in this PR is wrong. One should copy the logic of my "Redefine and Override annotation" PR. |
I don't think that's actually much helpful, it might rather be contraproductive at times. When a method is overriden in a child class, it usually changes behaviour from the parent implementation. This could either be only internal changes, not worth mentioning. Then just inheriting the parent's docs is enough. The can be achieved with either |
My use case for For now, we have documented methods that often delegate to another type/module under the I'm fine with always copying the docs from an abstract method when it's implemented, or make it explicit with |
@ysbaddaden In your And honestly I can't see any benefit over documenting a public API method which calls a private implementation method defined in |
Sorry about jumping the gun on this PR, I knew like right after uploading that my implementation wasn't going to cut it. I'll do more thorough testing and research next time. I was going to begin working on this now, but I saw @asterite 's #6989 and I like that syntax way better than the one suggested by @bew that inspired this PR. |
@dscottboggs thanks a lot for making this PR! The compiler is a very complex piece of code. |
@dscottboggs Also it's thanks to you I decided to tackle these issues myself :-) |
This issue came to my attention and I thought I'd take a stab at it. I hope this solution works, and is the way you want to go about resolving this issue.