castwide / solargraph

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

Process non-self singleton classes #581

Closed k0kubun closed 1 year ago

k0kubun commented 2 years ago

To avoid deep indentation while still using private and skipping def self., I sometimes declare a class and define singleton methods on it with class << Example = Class.new. I'd like Solargraph to process its children.

class << Example = Class.new
  def foo
    bar
  end

  private

  def bar
    "example"
  end
end

The current SclassNodes supports only class << self, so I extended it to handle the above CDECL case as well as CONST case, .e.g. class << Example.

k0kubun commented 1 year ago

@castwide Any thoughts? I'll close this if you're uncomfortable with supporting this feature. I use this syntax in many of my projects and it's been painful whenever solargraph without this is installed.

castwide commented 1 year ago

I've been meaning to support this for a while. Thanks for taking care of it.