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

Tie plugins' pluginModifyDynflags to their enabled state #2029

Merged
merged 5 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import Database.SQLite.Simple
import HieDb.Create
import HieDb.Types
import HieDb.Utils
import Ide.Types (dynFlagsModifyGlobal)

-- | Bump this version number when making changes to the format of the data stored in hiedb
hiedbDataVersion :: String
Expand Down Expand Up @@ -283,8 +282,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
packageSetup (hieYaml, cfp, opts, libDir) = do
-- Parse DynFlags for the newly discovered component
hscEnv <- emptyHscEnv ideNc libDir
(df, targets) <- evalGhcEnv hscEnv $
first (dynFlagsModifyGlobal optModifyDynFlags) <$> setOptions opts (hsc_dflags hscEnv)
(df, targets) <- evalGhcEnv hscEnv $ setOptions opts (hsc_dflags hscEnv)
let deps = componentDependencies opts ++ maybeToList hieYaml
dep_info <- getDependencyInfo deps
-- Now lookup to see whether we are combining with an existing HscEnv
Expand Down
5 changes: 4 additions & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ getParsedModuleWithCommentsRule =
liftIO $ fmap (fmap reset_ms) $ snd <$> getParsedModuleDefinition (hscEnv sess) opt file ms

getModifyDynFlags :: (DynFlagsModifications -> a) -> Action a
getModifyDynFlags f = f . optModifyDynFlags <$> getIdeOptions
getModifyDynFlags f = do
opts <- getIdeOptions
cfg <- getClientConfigAction def
pure $ f $ optModifyDynFlags opts cfg


getParsedModuleDefinition
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import qualified Language.LSP.Server as LSP
data Plugin c = Plugin
{pluginRules :: Rules ()
,pluginHandlers :: LSP.Handlers (ServerM c)
,pluginModifyDynflags :: DynFlagsModifications
,pluginModifyDynflags :: c -> DynFlagsModifications
}

instance Default (Plugin c) where
Expand Down
9 changes: 8 additions & 1 deletion ghcide/src/Development/IDE/Plugin/HLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ rulesPlugins rs = mempty { P.pluginRules = rules }
rules = foldMap snd rs

dynFlagsPlugins :: [(PluginId, DynFlagsModifications)] -> Plugin Config
dynFlagsPlugins rs = mempty { P.pluginModifyDynflags = foldMap snd rs }
dynFlagsPlugins rs = mempty
{ P.pluginModifyDynflags =
flip foldMap rs $ \(plId, dflag_mods) cfg ->
let plg_cfg = configForPlugin cfg plId
in if plcGlobalOn plg_cfg
then dflag_mods
else mempty
}

-- ---------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Types/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data IdeOptions = IdeOptions
-- Otherwise, return the result of parsing without Opt_Haddock, so
-- that the parsed module contains the result of Opt_KeepRawTokenStream,
-- which might be necessary for hlint.
, optModifyDynFlags :: DynFlagsModifications
, optModifyDynFlags :: Config -> DynFlagsModifications
-- ^ Will be called right after setting up a new cradle,
-- allowing to customize the Ghc options used
, optShakeOptions :: ShakeOptions
Expand Down