solargraph
solargraph copied to clipboard
Use presence information to improve local variable type probing
Use Pin::LocalVariable#combine_with to merge information from multiple assignments to the same local variable that may be visible from a given location, offering a single pin with consolidated information with ApiMap#var_at_location.
This, combined with #1114 and #1119, enables even more flow-sensitive typing scenarios, making nil-checking more accurate. Examples from a dev branch of enabled scenarios:
- https://github.com/apiology/solargraph/pull/12/files#diff-3b9f8c380cdc1c72488521dd85cf2734e79adb62667b46a77118fdd23da40773
- https://github.com/apiology/solargraph/pull/12/files#diff-62478b9754564728fd1ec39277d0469b2c8241027d156f142b4256ce74bf2316
Fixes needed to make that happen:
- fix: Handle a number of Pin::Block rebinding cases more consistently so that we can rely on the closure information inside to determine visibility of assignments.
- fix: Ensure Pin::Base#reset_generated! gets called consistently when information is invalidated so that rebinding cases work more consistently.
- fix: Ensure #reduce_class_type is in both ComplexType and UniqueType, a bug this PR tickled
- fix: Track location information more consistently so that we can use it to determine visibility of assignments.
Points to pending external release:
- https://github.com/lekemula/solargraph-rspec/pull/30 - direct manipulation of the
@closureand@locationprivate instance variable meant that we didn't have a chance to refresh our cached derived state. This PR adds a new public API that will be used when available by solargraph-rspec (tested with.responds_to?)
Includes for better testing:
- https://github.com/castwide/solargraph/pull/1087
Includes for convenience:
- Improve some Pin::Base#inspect representations for easier debugging.
- https://github.com/castwide/solargraph/pull/1102
- https://github.com/castwide/solargraph/pull/1001