Skip to content

Commit

Permalink
Fix compatibility with GHC 9.4 and rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Dec 1, 2024
1 parent af9cd22 commit 6b1f66e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions ghcide/src/Development/IDE/GHC/Compat/Error.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}
module Development.IDE.GHC.Compat.Error (
-- * Top-level error types and lens for easy access
MsgEnvelope(..),
Expand All @@ -7,7 +8,7 @@ module Development.IDE.GHC.Compat.Error (
-- * Error messages for the typechecking and renamer phase
TcRnMessage (..),
TcRnMessageDetailed (..),
flatTcRnMessage,
stripTcRnMessageContext,
-- * Parsing error message
PsMessage(..),
-- * Desugaring diagnostic
Expand Down Expand Up @@ -52,13 +53,15 @@ _GhcDriverMessage = prism' GhcDriverMessage (\case
-- | Some 'TcRnMessage's are nested in other constructors for additional context.
-- For example, 'TcRnWithHsDocContext' and 'TcRnMessageWithInfo'.
-- However, in some occasions you don't need the additional context and you just want
-- the error message. @'flatTcRnMessage'@ recursively unwraps these constructors,
-- the error message. @'stripTcRnMessageContext'@ recursively unwraps these constructors,
-- until there are no more constructors with additional context.
--
flatTcRnMessage :: TcRnMessage -> TcRnMessage
flatTcRnMessage = \case
TcRnWithHsDocContext _ tcMsg -> flatTcRnMessage tcMsg
TcRnMessageWithInfo _ (TcRnMessageDetailed _ tcMsg) -> flatTcRnMessage tcMsg
stripTcRnMessageContext :: TcRnMessage -> TcRnMessage
stripTcRnMessageContext = \case
#if MIN_VERSION_ghc(9, 6, 1)
TcRnWithHsDocContext _ tcMsg -> stripTcRnMessageContext tcMsg
#endif
TcRnMessageWithInfo _ (TcRnMessageDetailed _ tcMsg) -> stripTcRnMessageContext tcMsg
msg -> msg

msgEnvelopeErrorL :: Lens' (MsgEnvelope e) e
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Types/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ instance NFData ShowDiagnostic where
--
-- This produces a value of type `Maybe TcRnMessage`.
--
-- Further, consider utility functions such as 'flatTcRnMessage', which strip
-- Further, consider utility functions such as 'stripTcRnMessageContext', which strip
-- context from error messages which may be more convenient in certain situations.
data StructuredMessage
= NoStructuredMessage
Expand Down
4 changes: 2 additions & 2 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Development.IDE.Core.PositionMapping (fromCurrentRange)
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.Error (TcRnMessage (..),
_TcRnMessage,
flatTcRnMessage,
stripTcRnMessageContext,
msgEnvelopeErrorL)
import Development.IDE.GHC.Compat.Util
import Development.IDE.Spans.AtPoint (pointCommand)
Expand Down Expand Up @@ -196,7 +196,7 @@ isClassMethodWarning message = case message ^? _SomeStructuredMessage . msgEnvel
Just tcRnMessage -> isUnsatisfiedMinimalDefWarning tcRnMessage

isUnsatisfiedMinimalDefWarning :: TcRnMessage -> Maybe ClassMinimalDef
isUnsatisfiedMinimalDefWarning = flatTcRnMessage >>> \case
isUnsatisfiedMinimalDefWarning = stripTcRnMessageContext >>> \case
TcRnUnsatisfiedMinimalDef classMinDef -> Just classMinDef

Check failure on line 200 in plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

Not in scope: data constructor ‘TcRnUnsatisfiedMinimalDef’

Check failure on line 200 in plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

Not in scope: data constructor ‘TcRnUnsatisfiedMinimalDef’

Check failure on line 200 in plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

Not in scope: data constructor ‘TcRnUnsatisfiedMinimalDef’

Check failure on line 200 in plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

Not in scope: data constructor ‘TcRnUnsatisfiedMinimalDef’
_ -> Nothing

Expand Down

0 comments on commit 6b1f66e

Please sign in to comment.