Skip to content
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

Typing a class instance variable #159

Open
jaredcwhite opened this issue Sep 21, 2022 · 3 comments
Open

Typing a class instance variable #159

jaredcwhite opened this issue Sep 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@jaredcwhite
Copy link

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 jaredcwhite added the enhancement New feature or request label Sep 21, 2022
@grncdr
Copy link

grncdr commented Sep 23, 2022

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.

@AaronC81
Copy link
Owner

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

@nogweii
Copy link

nogweii commented Oct 17, 2023

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]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants