Expose exhaustivity checks in the GHC API
I'm working on the Haskell Language Server, and would like to add functionality that creates missing matches for otherwise inexhaustive pattern matches. The right way to do this IMO is to reuse GHC's exhaustivity checking machinery, and to create new matches for the uncovered cases.
However, all of the machinery exposed by
GHC.HsToCore.PmCheck assumes the caller wants to just emit the warnings. Despite having a rich data structure below the surface, none of it is exposed, and is simply immediately consumed to produce warnings.
This leaves HLS in the unfortunate position of needing to parse error messages in order to get its hands on the exhaustivity data!
GHC.HsToCore.PmCheck.checkMatches', possibly with fewer assumptions baked in that callers want to immediately turn the result into a warning. E.g. I'm not convinced it needs to call
getNFirstUncovered, though this is based on a very cursory reading of the code.