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

Return type issues #1

Open
iftheshoefritz opened this issue Nov 8, 2020 · 3 comments
Open

Return type issues #1

iftheshoefritz opened this issue Nov 8, 2020 · 3 comments

Comments

@iftheshoefritz
Copy link
Owner

iftheshoefritz commented Nov 8, 2020

Solargraph isn't understanding what we send for column return value:

[Trace - 07:22:00 AM] Received response 'textDocument/hover - (35)' in 14ms.
Result: {
  "contents": {
    "value": "OtherModel#created_at\n\nReturns:\n* []\n\nVisibility: public",
    "kind": "markdown"
  }
}
@iftheshoefritz
Copy link
Owner Author

Types are coming back now, but something is going wrong with some types. If I call MyBook.new.author. my editor has no problem giving me string methods if that column is a String, but for most of the other types I'm not getting methods of those types back.

@iftheshoefritz iftheshoefritz changed the title Return types come back empty from Solargraph Return type issues Nov 20, 2020
@iftheshoefritz
Copy link
Owner Author

Fixed a bug where additional info in the annotation such as String(255) prevented a pin from being created, in 498ecb6.

@iftheshoefritz
Copy link
Owner Author

iftheshoefritz commented Nov 20, 2020

Still having a problem with BigDecimal. It seems like Solargraph just doesn't know about BigDecimal and its methods.

Created an issue here: castwide/solargraph#393

grncdr added a commit to grncdr/solargraph-rails that referenced this issue Sep 26, 2022
This a more accurate represenation of what ActiveRecord actually does at
runtime, and therefore gives better code suggestions when dealing with
associations and model classes.

I've settled on this as being the best compromise after trying a few
different approaches. There are two "challenges" that I believe can't be
met any other way (at this time).

1. It is not possible to write a return type annotation for the methods
   of various ActiveRecord mixins that will be correct for both a model
   class (e.g. Person.where) and relation (e.g. people.where). [0], [1]
2. It is not possible to represent ActiveRecords "class methods are also
   relation methods" behaviour without model-specific relation types.

It's conceivable that Solargraph could change it's interpretation of [self]
on class methods to solve challenge iftheshoefritz#1, but the second challenge really
forces our hand. In order to represent this correctly, Solargraph would
need support for method-missing delegation, **and** delegating those
missing methods to an associated/generic type.

Given @castwide is working on RBS support and the Ruby ecosystem is
likely to move that way in the future, it seems pragmatic to eat the
cost repetition / manual labour in this gem rather than try to push YARD
types into supporting that degree of type-level programming. 😅

[0]: castwide/solargraph#592
[1]: lsegal/yard#1257
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

1 participant