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

Question: Is it possible to define own generic/parameterized classes? #681

Open
lekemula opened this issue Aug 28, 2023 · 1 comment
Open

Comments

@lekemula
Copy link

lekemula commented Aug 28, 2023

Hi,

YARDoc supports parameterized types, although it doesn't really tell how to make use of them. Does solargraph support defining them somehow?

For example:

class SuccessResult < Result
  def initialize(value)
    @value = value
  end

  # @return ???
  attr_reader :value
end

# @return [SuccessResult<Integer>]
def my_method
  SuccessResult.new(1)
end

my_method.value
#         ^^^^^ Integer

Looking at typical Ruby's array example they seem to be parsed as following: Enumerator<param<Elem>>
image

But I haven't found anything in the docs that shows how can one define custom generic classes to make use of such parameterized types.

I also tried defining the .rbs types declaration which supports such a feature, but that didn't help either. I'm assuming the RBS integration is still in progress (?).

Thanks in advance for your answers!

@castwide
Copy link
Owner

castwide commented Nov 6, 2023

Solargraph has limited support for parameterized types, but it mainly works with core classes like Array and Set. RBS is indeed still in progress. The code maps currently don't use it for the current workspace or third-party gems.

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

No branches or pull requests

2 participants