Skip to content

Commit

Permalink
Tie plugins' pluginModifyDynflags to their enabled state (#2029)
Browse files Browse the repository at this point in the history
* wip config disabling

* Correctly disable dynflags when plugin is disabled

* Remove trace

* Fuck hlint
  • Loading branch information
isovector authored Jul 20, 2021
1 parent c78363f commit 78381b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
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

0 comments on commit 78381b8

Please sign in to comment.