Skip to content
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

Customizable TH warning #2781

Merged
merged 4 commits into from
Mar 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -828,22 +828,11 @@ getModIfaceFromDiskAndIndexRule recorder =

return (Just x)

displayTHWarning :: LspT c IO ()
displayTHWarning
| not isWindows && not hostIsDynamic = do
LSP.sendNotification SWindowShowMessage $
ShowMessageParams MtInfo $ T.unwords
[ "This HLS binary does not support Template Haskell."
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
, "to build an HLS binary with support for Template Haskell."
]
| otherwise = return ()

newtype DisplayTHWarning = DisplayTHWarning (IO ())
newtype DisplayTHWarning = DisplayTHWarning (IO())
instance IsIdeGlobal DisplayTHWarning

getModSummaryRule :: Recorder (WithPriority Log) -> Rules ()
getModSummaryRule recorder = do
getModSummaryRule :: LspT Config IO () -> Recorder (WithPriority Log) -> Rules ()
getModSummaryRule displayTHWarning recorder = do
menv <- lspEnv <$> getShakeExtrasRules
forM_ menv $ \env -> do
displayItOnce <- liftIO $ once $ LSP.runLspT env displayTHWarning
Expand Down Expand Up @@ -1103,9 +1092,23 @@ data RulesConfig = RulesConfig
checkForImportCycles :: Bool
-- | Disable TH for improved performance in large codebases
, enableTemplateHaskell :: Bool
-- | Warning to show when TH is not supported by the current HLS binary
, templateHaskellWarning :: LspT Config IO ()
}

instance Default RulesConfig where def = RulesConfig True True
instance Default RulesConfig where
def = RulesConfig True True displayTHWarning
where
displayTHWarning :: LspT c IO ()
displayTHWarning
| not isWindows && not hostIsDynamic = do
LSP.sendNotification SWindowShowMessage $
ShowMessageParams MtInfo $ T.unwords
[ "This HLS binary does not support Template Haskell."
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
, "to build an HLS binary with support for Template Haskell."
]
| otherwise = return ()

-- | A rule that wires per-file rules together
mainRule :: Recorder (WithPriority Log) -> RulesConfig -> Rules ()
Expand All @@ -1123,7 +1126,7 @@ mainRule recorder RulesConfig{..} = do
getModIfaceFromDiskRule recorder
getModIfaceFromDiskAndIndexRule recorder
getModIfaceRule recorder
getModSummaryRule recorder
getModSummaryRule templateHaskellWarning recorder
getModuleGraphRule recorder
knownFilesRule recorder
getClientSettingsRule recorder
Expand Down