sord icon indicating copy to clipboard operation
sord copied to clipboard

Typing a class instance variable

Open jaredcwhite opened this issue 3 years ago • 3 comments

This may be a limitation of YARD tags, but I have a module that's trying to set class instance variables, and I'm not sure how I can get those typings to be output by Sord. The RBS file needs to have something like this:

  module ClassMethods
    @tag_name: String

but how to get that instance variable definition in there is the question…

jaredcwhite avatar Sep 21 '22 19:09 jaredcwhite

there is some precedent with Solargraphs @type tag:

module ClassMethods
  # @type [String]
  @tag_name
end

It would be pretty cool if sord were to pick that up.

grncdr avatar Sep 23 '22 12:09 grncdr

Thanks for the suggestion - this would be neat!

Unfortunately, I'm not sure that YARD is actually aware of instance variables :( Sord doesn't parse the tags or Ruby code itself; it just loads the YARD registry, so can only use what's there. YARD appears to know about class variables, but I can't spot anything about instance variables in the API docs, nor does it seem to generate any docs for them (unless I'm doing it wrong):

image

AaronC81 avatar Sep 24 '22 22:09 AaronC81

A not-great workaround I've found is to use the @!attribute directive:

# @!attribute [r] http
#   @return [::HTTPX::Session]

But then that leads to the generated documentation mentioning it as, well, an attribute.

Would it make sense for sord to register a custom tag in YARD? Something like @itype name [String]?

nogweii avatar Oct 17 '23 08:10 nogweii