castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.87k stars 154 forks source link

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

Open lekemula opened 10 months ago

lekemula commented 10 months ago

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 commented 8 months ago

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.