Skip to content

Commit 7d106cf

Browse files
committed
fix duplication
1 parent 8957a42 commit 7d106cf

File tree

1 file changed

+9
-124
lines changed

1 file changed

+9
-124
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 9 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ import qualified Data.HashSet as Set
9191
import Database.SQLite.Simple
9292
import Development.IDE.Core.Tracing (withTrace)
9393
import Development.IDE.Core.WorkerThread (withWorkerQueue)
94-
import Development.IDE.Session.Diagnostics (renderCradleError)
9594
import Development.IDE.Session.Dependency
96-
import Development.IDE.Session.Ghc hiding (Log)
95+
import Development.IDE.Session.Diagnostics (renderCradleError)
96+
import Development.IDE.Session.Ghc hiding (Log)
9797
import Development.IDE.Types.Shake (WithHieDb,
9898
WithHieDbShield (..),
9999
toNoFileKey)
@@ -106,11 +106,11 @@ import Text.ParserCombinators.ReadP (readP_to_S)
106106

107107
import Control.Concurrent.STM (STM, TVar)
108108
import qualified Control.Monad.STM as STM
109+
import Control.Monad.Trans.Reader
110+
import qualified Development.IDE.Session.Ghc as Ghc
109111
import qualified Development.IDE.Session.OrderedSet as S
110112
import qualified Focus
111113
import qualified StmContainers.Map as STM
112-
import Control.Monad.Trans.Reader
113-
import qualified Development.IDE.Session.Ghc as Ghc
114114

115115
data Log
116116
= LogSettingInitialDynFlags
@@ -689,12 +689,12 @@ data SessionShake = SessionShake
689689
}
690690

691691
data SessionEnv = SessionEnv
692-
{ sessionLspContext :: Maybe (LanguageContextEnv Config)
693-
, sessionRootDir :: FilePath
694-
, sessionIdeOptions :: IdeOptions
695-
, sessionClientConfig :: Config
692+
{ sessionLspContext :: Maybe (LanguageContextEnv Config)
693+
, sessionRootDir :: FilePath
694+
, sessionIdeOptions :: IdeOptions
695+
, sessionClientConfig :: Config
696696
, sessionSharedNameCache :: NameCache
697-
, sessionLoadingOptions :: SessionLoadingOptions
697+
, sessionLoadingOptions :: SessionLoadingOptions
698698
}
699699

700700
type SessionM = ReaderT SessionEnv IO
@@ -1024,121 +1024,6 @@ memoIO op = do
10241024
return (Map.insert k res mp, res)
10251025
Just res -> return (mp, res)
10261026

1027-
unit_flags :: [Flag (CmdLineP [String])]
1028-
unit_flags = [defFlag "unit" (SepArg addUnit)]
1029-
1030-
addUnit :: String -> EwM (CmdLineP [String]) ()
1031-
addUnit unit_str = liftEwM $ do
1032-
units <- getCmdLineState
1033-
putCmdLineState (unit_str : units)
1034-
1035-
-- | Throws if package flags are unsatisfiable
1036-
setOptions :: GhcMonad m
1037-
=> NormalizedFilePath
1038-
-> ComponentOptions
1039-
-> DynFlags
1040-
-> FilePath -- ^ root dir, see Note [Root Directory]
1041-
-> m (NonEmpty (DynFlags, [GHC.Target]))
1042-
setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
1043-
((theOpts',_errs,_warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
1044-
case NE.nonEmpty units of
1045-
Just us -> initMulti us
1046-
Nothing -> do
1047-
(df, targets) <- initOne (map unLoc theOpts')
1048-
-- A special target for the file which caused this wonderful
1049-
-- component to be created. In case the cradle doesn't list all the targets for
1050-
-- the component, in which case things will be horribly broken anyway.
1051-
--
1052-
-- When we have a singleComponent that is caused to be loaded due to a
1053-
-- file, we assume the file is part of that component. This is useful
1054-
-- for bare GHC sessions, such as many of the ones used in the testsuite
1055-
--
1056-
-- We don't do this when we have multiple components, because each
1057-
-- component better list all targets or there will be anarchy.
1058-
-- It is difficult to know which component to add our file to in
1059-
-- that case.
1060-
-- Multi unit arguments are likely to come from cabal, which
1061-
-- does list all targets.
1062-
--
1063-
-- If we don't end up with a target for the current file in the end, then
1064-
-- we will report it as an error for that file
1065-
let abs_fp = toAbsolute rootDir (fromNormalizedFilePath cfp)
1066-
let special_target = Compat.mkSimpleTarget df abs_fp
1067-
pure $ (df, special_target : targets) :| []
1068-
where
1069-
initMulti unitArgFiles =
1070-
forM unitArgFiles $ \f -> do
1071-
args <- liftIO $ expandResponse [f]
1072-
-- The reponse files may contain arguments like "+RTS",
1073-
-- and hie-bios doesn't expand the response files of @-unit@ arguments.
1074-
-- Thus, we need to do the stripping here.
1075-
initOne $ HieBios.removeRTS $ HieBios.removeVerbosityOpts args
1076-
initOne this_opts = do
1077-
(dflags', targets') <- addCmdOpts this_opts dflags
1078-
let dflags'' =
1079-
case unitIdString (homeUnitId_ dflags') of
1080-
-- cabal uses main for the unit id of all executable packages
1081-
-- This makes multi-component sessions confused about what
1082-
-- options to use for that component.
1083-
-- Solution: hash the options and use that as part of the unit id
1084-
-- This works because there won't be any dependencies on the
1085-
-- executable unit.
1086-
"main" ->
1087-
let hash = B.unpack $ B16.encode $ H.finalize $ H.updates H.init (map B.pack this_opts)
1088-
hashed_uid = Compat.toUnitId (Compat.stringToUnit ("main-"++hash))
1089-
in setHomeUnitId_ hashed_uid dflags'
1090-
_ -> dflags'
1091-
1092-
let targets = makeTargetsAbsolute root targets'
1093-
root = case workingDirectory dflags'' of
1094-
Nothing -> compRoot
1095-
Just wdir -> compRoot </> wdir
1096-
let dflags''' =
1097-
setWorkingDirectory root $
1098-
disableWarningsAsErrors $
1099-
-- disabled, generated directly by ghcide instead
1100-
flip gopt_unset Opt_WriteInterface $
1101-
-- disabled, generated directly by ghcide instead
1102-
-- also, it can confuse the interface stale check
1103-
dontWriteHieFiles $
1104-
setIgnoreInterfacePragmas $
1105-
setBytecodeLinkerOptions $
1106-
disableOptimisation $
1107-
Compat.setUpTypedHoles $
1108-
makeDynFlagsAbsolute compRoot -- makeDynFlagsAbsolute already accounts for workingDirectory
1109-
dflags''
1110-
return (dflags''', targets)
1111-
1112-
setIgnoreInterfacePragmas :: DynFlags -> DynFlags
1113-
setIgnoreInterfacePragmas df =
1114-
gopt_set (gopt_set df Opt_IgnoreInterfacePragmas) Opt_IgnoreOptimChanges
1115-
1116-
disableOptimisation :: DynFlags -> DynFlags
1117-
disableOptimisation df = updOptLevel 0 df
1118-
1119-
setHiDir :: FilePath -> DynFlags -> DynFlags
1120-
setHiDir f d =
1121-
-- override user settings to avoid conflicts leading to recompilation
1122-
d { hiDir = Just f}
1123-
1124-
setODir :: FilePath -> DynFlags -> DynFlags
1125-
setODir f d =
1126-
-- override user settings to avoid conflicts leading to recompilation
1127-
d { objectDir = Just f}
1128-
1129-
getCacheDirsDefault :: String -> [String] -> IO CacheDirs
1130-
getCacheDirsDefault prefix opts = do
1131-
dir <- Just <$> getXdgDirectory XdgCache (cacheDir </> prefix ++ "-" ++ opts_hash)
1132-
return $ CacheDirs dir dir dir
1133-
where
1134-
-- Create a unique folder per set of different GHC options, assuming that each different set of
1135-
-- GHC options will create incompatible interface files.
1136-
opts_hash = B.unpack $ B16.encode $ H.finalize $ H.updates H.init (map B.pack opts)
1137-
1138-
-- | Sub directory for the cache path
1139-
cacheDir :: String
1140-
cacheDir = "ghcide"
1141-
11421027
----------------------------------------------------------------------------------------------------
11431028

11441029
data PackageSetupException

0 commit comments

Comments
 (0)