Skip to content

Commit 869edd6

Browse files
dylan-thinnesJaro Reinders
authored and
Jaro Reinders
committed
Revert "Drop attachReason logic", needed by pragmas-plugin
This reverts commit 4fed987.
1 parent 79fd77e commit 869edd6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

ghcide/src/Development/IDE/GHC/Warnings.hs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
module Development.IDE.GHC.Warnings(withWarnings) where
77

88
import Control.Concurrent.Strict
9+
import Control.Lens (over)
10+
import Data.List
911
import qualified Data.Text as T
1012

1113
import Development.IDE.GHC.Compat
1214
import Development.IDE.GHC.Error
1315
import Development.IDE.Types.Diagnostics
16+
import Language.LSP.Protocol.Types (type (|?) (..))
1417

1518

1619
-- | Take a GHC monadic action (e.g. @typecheckModule pm@ for some
@@ -27,9 +30,30 @@ withWarnings diagSource action = do
2730
warnings <- newVar []
2831
let newAction :: DynFlags -> LogActionCompat
2932
newAction dynFlags logFlags wr _ loc prUnqual msg = do
30-
let wr_d = map (wr,) $ diagFromSDocErrMsg diagSource dynFlags (mkWarnMsg dynFlags wr logFlags loc prUnqual msg)
33+
let wr_d = map ((wr,) . over fdLspDiagnosticL (attachReason wr)) $ diagFromSDocErrMsg diagSource dynFlags (mkWarnMsg dynFlags wr logFlags loc prUnqual msg)
3134
modifyVar_ warnings $ return . (wr_d:)
3235
newLogger env = pushLogHook (const (logActionCompat (newAction (hsc_dflags env)))) (hsc_logger env)
3336
res <- action $ \env -> putLogHook (newLogger env) env
3437
warns <- readVar warnings
3538
return (reverse $ concat warns, res)
39+
40+
#if MIN_VERSION_ghc(9,3,0)
41+
attachReason :: Maybe DiagnosticReason -> Diagnostic -> Diagnostic
42+
attachReason Nothing d = d
43+
attachReason (Just wr) d = d{_code = InR <$> showReason wr}
44+
where
45+
showReason = \case
46+
WarningWithFlag flag -> showFlag flag
47+
_ -> Nothing
48+
#else
49+
attachReason :: WarnReason -> Diagnostic -> Diagnostic
50+
attachReason wr d = d{_code = InR <$> showReason wr}
51+
where
52+
showReason = \case
53+
NoReason -> Nothing
54+
Reason flag -> showFlag flag
55+
ErrReason flag -> showFlag =<< flag
56+
#endif
57+
58+
showFlag :: WarningFlag -> Maybe T.Text
59+
showFlag flag = ("-W" <>) . T.pack . flagSpecName <$> find ((== flag) . flagSpecFlag) wWarningFlags

0 commit comments

Comments
 (0)