-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Integrate GHC's new diagnostic infrastructure #2014
Comments
A simpler path for 2 is possible if we assume that |
Hello @pepeiborra , thanks for chiming in!
Thanks, I'll take a look, although I think I came across something similar (if not the same
Yes, that matches roughly my superficial understanding as well!
In theory, and this applies to
Hehe no, structured diagnostics are now pervasive. You will get them even if GHC throws an exception (like it likes to do in |
Our team would love to work on this! |
I am happy to provide feedback and code reviews. Preferably work on HEAD as much as possible, a branch should be only a last resort. @fendor is already working on 9.2 compatibility |
Sorry, that was a mouthful expression. I was asking if I should create a new HLS branch to stage the latest GHC HEAD support into HLS. This branch should still rebase on HLS's |
Sorry I wasn't clear - my recommendation is to use compatibility modules ( |
Oh, I see, that was my plan too. To target only affected packages, piece by piece! |
Nah, I took the bold route and am SYBing the AST to find holes. #yolo |
@kk-hainq Thanks so much for stepping up here! If there's anything on the GHC end that would be helpful to you, please ask. (I sometimes drown in GitHub etc notifications, so if need be, just send a direct email.) |
Thanks! We've just booked https://gitlab.haskell.org/ghc/ghc/-/issues/20118 too. This whole error-as-structured-type project is awesome. Hope we can help complete it all the way from GHC to HLS, HLint, etc. |
What is the status of this? Would it be suitable for a GSoC project? /cc @jneira @jaspervdj |
Working on this for ZuriHac |
Hello folks,
This is a meta ticket, feel free to close it if you think this is not the appropriate place to discuss the subject.
Summary: GHC changed how diagnostics are emitted, HLS can benefit from this, help needed to integrate the work and feedback welcome to improve GHC to best serve HLS.
Well-Typed has been working together with @goldfirere for the past few months on what used to be GHC proposal 306, i.e. refactor GHC so that it would emit richer Haskell types instead of
SDoc
s for its diagnostic messages. Since the original GHC ticket (cfr. ghc#18516) and the inception of our work, we tried to do our best to keep in mind HLS and Haskell IDEs in general as the primary consumers/beneficiaries of this work. The Wiki page goes a bit deeper into the original design work, if people are interested.I think we are now at a stage where it would be nice to start thinking how we can collectively integrate this into HLS and what we can learn from this exercise so that we can improve what we have already in GHC before 9.4 (that would be nice but not strictly required, I guess).
30 seconds overview
To give you a 30 seconds overview of GHC's
HEAD
, we now have a typeclass:And a bunch of types that implement instances for it, which forms a hierarchy:
GHC now emits these types (each individually wrapped in a
MsgEnvelope
which gives youSeverity
and aSrcSpan
amongst other things) which can be "queried" to get not just the pretty-printed message but also the reason why it arose (it will include aWarningFlag
if this is a warning) and a list ofGhcHint
. Furthermore, both these types andGhcHint
will include proper information about the diagnostic: for example, if this is a message coming from the type checker about unused pattern binds, GHC will emit aTcRnUnusedPatternBinds :: HsBind GhcRn -> TcRnMessage
that will give the caller the actual binds, not just a list ofSDoc
. TheGhcHint
type follows a similar logic, for example GHC might emit[SuggestExtension LangExt.BangPatterns]
.Little disclaimer
Currently not all diagnostics have been ported within GHC (due to their sheer amount). For some of those, we still have the old
SDoc
wrapped into a constructor (specific to the type of message we want to emit), like, for example aTcRnUnknownMessage :: SDoc -> TcRnMessage
. Similarly, not all diagnostics have a proper list of hints attached to them, for some not-yet-ported or not-fully-ported, we still have the hints bundled with the pretty-printed message (i.e. thediagnosticMessage
). We are actively working on this.Where to go from here
The idea would be for HLS to use this information directly instead of parsing and using regexes on the raw output of the compiler. In a GHC meta-ticket about the "remaining work" (see "Little Disclaimer" section) @wz1000 and @bgamari suggested to look at the error parsing logic in
ghcide
to see if we can get rid of all those "matchRegex" calls and just use the new infrastructure.I wanted to have some fun taking a crack at it (as a proof-of-concept, mostly), but it revealed to be harder than I was expecting, mostly due to the perfect storm arising from the changes between GHC 9.2 and 9.3/HEAD (including Alan's work on exactprint) and the changes to
Data.List
and its import which broke virtually all the packages I have tried to build. Despite I have used the patched versions of @fendor I have found online, having a working version ofghcide
built withHEAD
was too hard and I have abandoned ship, but I am happy to be told I was doing it all wrong and there is a branch that magically compiles :)Having said that, I've started taking a cursory look at the
CodeAction.hs
module, and the first thing that stood out was that currentlyghcide
is running regexes on the_message
field on theDiagnostic
type, which comes fromlsp
:Here
_message
isText
whereas we would need to be given something more structured. @wz1000 pointed out (in the same GHC 19905 issue) that we can change this, but rather than keeping this conversation tucked into the GHC issue tracker, I wanted to share this on this repo to collect feedback and useful pointers on how we could push the work forward. Again, from a super quick look atghcide
codebase it seems like theIdeResult
type could be changed to return not just aDiagnostic
but aGhcMessage
, which we would get (almost) from free from GHC'stcRnModule
(inHEAD
, that is):Therefore, concretely, I guess what I am asking is the following:
What would be the least painful way to try out whether GHC is solving HLS/ghcide's actual problems? Is
there some magical fork targeting GHC
HEAD
somewhere?What would be the required steps to feed
ghcide
with structured types instead of a textual_message
?Is there any other place apart form the
CodeAction.hs
we should focus or lens on to understand if the GHC work is going into the right direction?Thanks in advance! 😉
The text was updated successfully, but these errors were encountered: