-
Notifications
You must be signed in to change notification settings - Fork 136
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
Provide a Gradualizer diagnostic #1117
Conversation
Thanks for this, amazing stuff! I asked in our Slack channel what's the Community view on this. I will also take it with the other core maintainers and come back to you shortly :) |
For visibility, copying from Slack:
|
Also, I briefly tried the Gradualizer on the Erlang LS project itself and I noticed a couple of things:
|
Thanks for the feedback!
I haven't seen this happening, but I'm not saying it's not - could you provide an example?
Good catch! Fixed now. I've added the dependency on Gradualizer, but maybe it's worth waiting for josefs/Gradualizer#358 before merging this one. |
The warnings cleanup in Gradualizer is merged, so I'm clicking "Ready for review" :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a couple of questions and nits that can eventually be addressed as follow ups.
-spec start_and_load() -> boolean(). | ||
start_and_load() -> | ||
try application:ensure_all_started(gradualizer) of | ||
{ok, [gradualizer]} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle this could fail if, for example, gradualizer had an additional dependency which was not started. Maybe relax the matching to an {ok, _}
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I wonder if we shouldn't execute this only once during the negotiation phase between client and server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gradualizer is written with no runtime dependencies other than OTP libs. This check, together with the second clause {ok, []}
, effectively makes this code run only the first time start_and_load
is called.
FmtError = gradualizer_fmt:format_type_error(Error, FmtOpts), | ||
case re:run(FmtError, "([0-9]+):([0-9]+:)? (.*)", | ||
[{capture, all_but_first, binary}, dotall]) of | ||
{match, [BinLine, _BinCol, Msg]} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't the column be used for the diagnostic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had some trouble making this work reliably, but I don't remember the details. I think this is something worth working out in the future, but is not critical for getting the warnings - they're just reported at line granularity for now.
Having applied the fixes and added Gradualizer as a Rebar3 dependency, I'm getting an unexpected warning that
for
|
Ok, problem solved. This was an Erlang LS config mistake on my side. It should be:
NOT:
And if Gradualizer is also added as a project dependency, then |
Thanks! |
This implements a basic Gradualizer diagnostic for Erlang LS we, i.e. @garazdawi, Ferenc Pesti and I, built during an Erlang Solutions internal hackathon early this year. Some example screenshots of this integration in action can be seen here - josefs/Gradualizer#344 (comment).
I'm creating this as a draft, since I'm not sure what's the best way to express the dependency on Gradualizer - currently even the newly added test won't pass, since I haven't added Gradualizer to Rebar3 deps. What's the best approach for adding dependencies for optional diagnostics?
Important: Gradualizer, while being continuously improved, is still a work in progress and doesn't successfully self-gradualize yet. It's already useful, but it might also be misleading at times. That being said, I think having the integration in place is worth the effort, as it makes trying out the project and contributing easier.