Skip to content

Commit b02ce31

Browse files
pepeiborrawz1000
authored andcommitted
customizable TH warning (haskell#2781)
Co-authored-by: wz1000 <[email protected]>
1 parent 4c18651 commit b02ce31

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

ghcide/src/Development/IDE/Core/Rules.hs

+19-16
Original file line numberDiff line numberDiff line change
@@ -828,22 +828,11 @@ getModIfaceFromDiskAndIndexRule recorder =
828828

829829
return (Just x)
830830

831-
displayTHWarning :: LspT c IO ()
832-
displayTHWarning
833-
| not isWindows && not hostIsDynamic = do
834-
LSP.sendNotification SWindowShowMessage $
835-
ShowMessageParams MtInfo $ T.unwords
836-
[ "This HLS binary does not support Template Haskell."
837-
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
838-
, "to build an HLS binary with support for Template Haskell."
839-
]
840-
| otherwise = return ()
841-
842-
newtype DisplayTHWarning = DisplayTHWarning (IO ())
831+
newtype DisplayTHWarning = DisplayTHWarning (IO())
843832
instance IsIdeGlobal DisplayTHWarning
844833

845-
getModSummaryRule :: Recorder (WithPriority Log) -> Rules ()
846-
getModSummaryRule recorder = do
834+
getModSummaryRule :: LspT Config IO () -> Recorder (WithPriority Log) -> Rules ()
835+
getModSummaryRule displayTHWarning recorder = do
847836
menv <- lspEnv <$> getShakeExtrasRules
848837
forM_ menv $ \env -> do
849838
displayItOnce <- liftIO $ once $ LSP.runLspT env displayTHWarning
@@ -1103,9 +1092,23 @@ data RulesConfig = RulesConfig
11031092
checkForImportCycles :: Bool
11041093
-- | Disable TH for improved performance in large codebases
11051094
, enableTemplateHaskell :: Bool
1095+
-- | Warning to show when TH is not supported by the current HLS binary
1096+
, templateHaskellWarning :: LspT Config IO ()
11061097
}
11071098

1108-
instance Default RulesConfig where def = RulesConfig True True
1099+
instance Default RulesConfig where
1100+
def = RulesConfig True True displayTHWarning
1101+
where
1102+
displayTHWarning :: LspT c IO ()
1103+
displayTHWarning
1104+
| not isWindows && not hostIsDynamic = do
1105+
LSP.sendNotification SWindowShowMessage $
1106+
ShowMessageParams MtInfo $ T.unwords
1107+
[ "This HLS binary does not support Template Haskell."
1108+
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
1109+
, "to build an HLS binary with support for Template Haskell."
1110+
]
1111+
| otherwise = return ()
11091112

11101113
-- | A rule that wires per-file rules together
11111114
mainRule :: Recorder (WithPriority Log) -> RulesConfig -> Rules ()
@@ -1123,7 +1126,7 @@ mainRule recorder RulesConfig{..} = do
11231126
getModIfaceFromDiskRule recorder
11241127
getModIfaceFromDiskAndIndexRule recorder
11251128
getModIfaceRule recorder
1126-
getModSummaryRule recorder
1129+
getModSummaryRule templateHaskellWarning recorder
11271130
getModuleGraphRule recorder
11281131
knownFilesRule recorder
11291132
getClientSettingsRule recorder

0 commit comments

Comments
 (0)