solargraph icon indicating copy to clipboard operation
solargraph copied to clipboard

undefined method `domains' for Solargraph::Pin::Method

Open nickpelone opened this issue 5 years ago • 4 comments

Hey there! Thanks again for the gem. With 0.39.3 I'm getting a crash when trying to start up the language server. I use the # @!domain directive in my code some to add some DSL stuff into "scope". (Also as an aside question, are those "scoped" to the block they're put before, or do they operate "globally" in the file?)

[Error - 11:42:34 AM] Server initialization failed.
  Message: [NoMethodError] undefined method `domains' for #<Solargraph::Pin::Method:0x00007ff7c7893610>
  Code: -32603

nickpelone avatar Apr 28 '20 15:04 nickpelone

The @!domain tag could probably use some tweaking.

In many cases, you're probably better off using standard YARD to get the same functionality. For example, you could use the @!parse directive to virtually extend a class:

class Example
  # @!parse extend My::DSL::Module
end

On the other hand, a possible reason to use @!domain is that it only adds the module's public methods to the scope, while include and extend add private methods.

Currently, @!domain is scoped to the associated class or module.

# @!domain [My::DSL::Module]
class Example
  # My::DSL::Module public methods are visible here

  # @!domain [My::DSL::Module] <- Bug: this causes an error
  def method
  end
end

There's partial support for adding domains at the file level, but it's pretty wonky at the moment. If that would be useful to you, I should be able to make it work pretty easily.

castwide avatar Apr 28 '20 21:04 castwide

Oh ok, thanks for the clarification - and actually I'm fine with the current behavior, I was just curious as to the exact mechanics by which it "added stuff into scope".

I can move to # @!parse (I use it elsewhere in some of my code), but if # @!domain is gonna stick around as well, I would be happy to see it working again.

Thanks for all you do - I still owe you some Patreon support after I promised it a long time ago - work finally signed off to support, so hopefully next time I can actually go to the office (damn you COVID-19!) I can get that going. Really, really appreciate your work on this project, it has made my work so much more pain-free.

nickpelone avatar Apr 28 '20 22:04 nickpelone

I hate to necrobump this, but is there any hope of getting this fixed or should I migrate code to use # @!parse? I've had to hold off on upgrades to Solargraph this year basically to keep those annotations working in my large codebase. If it's dead, that's fine, I just need to go ahead and do the work to migrate.

Of course as usual, thanks for all you do.

nickpelone avatar Dec 17 '20 18:12 nickpelone

In most cases, I've found that the advantages of using @!parse instead of @!domain outweigh the disadvantages. I created @!domain to solve a fairly specific problem in one of my projects, and even there I've mostly migrated to either @!parse or the custom @yieldself tag, which solves a similar problem in a narrower scope.

If you have a use case where @!domain would work better, we can discuss ways to fix it, but in the meantime I'd say it's a candidate for deprecation.

castwide avatar Dec 17 '20 18:12 castwide