@@ -15,11 +15,11 @@ import Control.Concurrent.Extra
1515import Control.Exception
1616import Control.Monad.Extra
1717import Control.Monad.IO.Class
18- import qualified Crypto.Hash.SHA1 as H
19- import Data.ByteString.Base16
20- import qualified Data.ByteString.Char8 as B
18+ -- import qualified Crypto.Hash.SHA1 as H
19+ -- import Data.ByteString.Base16
20+ -- import qualified Data.ByteString.Char8 as B
2121import Data.Default
22- import Data.Functor ((<&>) )
22+ -- import Data.Functor ((<&>))
2323import qualified Data.HashSet as HashSet
2424import Data.List.Extra
2525import qualified Data.Map.Strict as Map
@@ -43,24 +43,26 @@ import Development.IDE.Types.Diagnostics
4343import Development.IDE.Types.Location
4444import Development.IDE.Types.Logger
4545import Development.IDE.Types.Options
46- import Development.Shake (Action , Rules , action , doesFileExist , doesDirectoryExist , need )
47- import DynFlags
48- import GHC hiding (def )
46+ import Development.Shake (Action , Rules , action )
47+ -- import DynFlags
48+ -- import GHC hiding (def)
4949-- import qualified GHC.Paths
5050import HIE.Bios
51- import HIE.Bios.Cradle
52- import HIE.Bios.Environment
53- import HIE.Bios.Types
51+ import qualified Language.Haskell.LSP.Core as LSP
52+ -- import HIE.Bios.Cradle
53+ -- import HIE.Bios.Environment
54+ -- import HIE.Bios.Types
5455import Ide.Plugin
5556-- import Ide.PluginDescriptors
5657import Ide.Plugin.Config
5758-- import Ide.Plugin.Formatter
5859import Language.Haskell.LSP.Messages
5960import Language.Haskell.LSP.Types (LspId (IdInt ))
60- import qualified Language.Haskell.LSP.Core as LSP
61- import Linker
61+ -- import qualified Language.Haskell.LSP.Core as LSP
62+ -- import Linker
6263-- import Paths_haskell_language_server
6364import RuleTypes
65+ import Rules
6466import qualified System.Directory.Extra as IO
6567-- import System.Environment
6668import System.Exit
@@ -139,6 +141,7 @@ idePlugins includeExamples
139141
140142-- ---------------------------------------------------------------------
141143-- Prefix for the cache path
144+ {-
142145cacheDir :: String
143146cacheDir = "ghcide"
144147
@@ -148,7 +151,7 @@ getCacheDir opts = IO.getXdgDirectory IO.XdgCache (cacheDir </> opts_hash)
148151 -- Create a unique folder per set of different GHC options, assuming that each different set of
149152 -- GHC options will create incompatible interface files.
150153 opts_hash = B.unpack $ encode $ H.finalize $ H.updates H.init (map B.pack opts)
151-
154+ -}
152155
153156main :: IO ()
154157main = do
@@ -184,6 +187,7 @@ main = do
184187 let options = (defaultIdeOptions $ loadSession dir)
185188 { optReportProgress = clientSupportsProgress caps
186189 , optShakeProfiling = argsShakeProfiling
190+ , optTesting = IdeTesting argsTesting
187191 }
188192 debouncer <- newAsyncDebouncer
189193 initialise caps (cradleRules >> mainRule >> pluginRules plugins >> action kick)
@@ -239,7 +243,7 @@ main = do
239243
240244cradleRules :: Rules ()
241245cradleRules = do
242- loadGhcSessionIO
246+ loadGhcSession
243247 cradleToSession
244248
245249expandFiles :: [FilePath ] -> IO [FilePath ]
@@ -267,95 +271,6 @@ showEvent lock (EventFileDiagnostics (toNormalizedFilePath -> file) diags) =
267271 withLock lock $ T. putStrLn $ showDiagnosticsColored $ map (file,ShowDiag ,) diags
268272showEvent lock e = withLock lock $ print e
269273
270-
271- loadGhcSessionIO :: Rules ()
272- loadGhcSessionIO =
273- -- This rule is for caching the GHC session. E.g., even when the cabal file
274- -- changed, if the resulting flags did not change, we would continue to use
275- -- the existing session.
276- defineNoFile $ \ (GetHscEnv opts deps) ->
277- liftIO $ createSession $ ComponentOptions opts deps
278-
279-
280- getComponentOptions :: Cradle a -> IO ComponentOptions
281- getComponentOptions cradle = do
282- let showLine s = putStrLn (" > " ++ s)
283- -- WARNING 'runCradle is very expensive and must be called as few times as possible
284- cradleRes <- runCradle (cradleOptsProg cradle) showLine " "
285- case cradleRes of
286- CradleSuccess r -> pure r
287- CradleFail err -> throwIO err
288- -- TODO Rather than failing here, we should ignore any files that use this cradle.
289- -- That will require some more changes.
290- CradleNone -> fail " 'none' cradle is not yet supported"
291-
292-
293- createSession :: ComponentOptions -> IO HscEnvEq
294- createSession (ComponentOptions theOpts _) = do
295- libdir <- getLibdir
296-
297- cacheDir <- Main. getCacheDir theOpts
298-
299- env <- runGhc (Just libdir) $ do
300- dflags <- getSessionDynFlags
301- (dflags', _targets) <- addCmdOpts theOpts dflags
302- _ <- setSessionDynFlags $
303- -- disabled, generated directly by ghcide instead
304- flip gopt_unset Opt_WriteInterface $
305- -- disabled, generated directly by ghcide instead
306- -- also, it can confuse the interface stale check
307- dontWriteHieFiles $
308- setHiDir cacheDir $
309- setDefaultHieDir cacheDir $
310- setIgnoreInterfacePragmas $
311- setLinkerOptions $
312- disableOptimisation dflags'
313- getSession
314- initDynLinker env
315- newHscEnvEq env
316-
317- -- we don't want to generate object code so we compile to bytecode
318- -- (HscInterpreted) which implies LinkInMemory
319- -- HscInterpreted
320- setLinkerOptions :: DynFlags -> DynFlags
321- setLinkerOptions df = df {
322- ghcLink = LinkInMemory
323- , hscTarget = HscNothing
324- , ghcMode = CompManager
325- }
326-
327- setIgnoreInterfacePragmas :: DynFlags -> DynFlags
328- setIgnoreInterfacePragmas df =
329- gopt_set (gopt_set df Opt_IgnoreInterfacePragmas ) Opt_IgnoreOptimChanges
330-
331- disableOptimisation :: DynFlags -> DynFlags
332- disableOptimisation df = updOptLevel 0 df
333-
334- setHiDir :: FilePath -> DynFlags -> DynFlags
335- setHiDir f d =
336- -- override user settings to avoid conflicts leading to recompilation
337- d { hiDir = Just f}
338-
339- cradleToSession :: Rules ()
340- cradleToSession = define $ \ LoadCradle nfp -> do
341- let f = fromNormalizedFilePath nfp
342-
343- -- If the path points to a directory, load the implicit cradle
344- mbYaml <- doesDirectoryExist f <&> \ isDir -> if isDir then Nothing else Just f
345- cradle <- liftIO $ maybe (loadImplicitCradle $ addTrailingPathSeparator f) loadCradle mbYaml
346-
347- cmpOpts <- liftIO $ getComponentOptions cradle
348- let opts = componentOptions cmpOpts
349- deps = componentDependencies cmpOpts
350- deps' = case mbYaml of
351- -- For direct cradles, the hie.yaml file itself must be watched.
352- Just yaml | isDirectCradle cradle -> yaml : deps
353- _ -> deps
354- existingDeps <- filterM doesFileExist deps'
355- need existingDeps
356- ([] ,) . pure <$> useNoFile_ (GetHscEnv opts deps)
357-
358-
359274loadSession :: FilePath -> Action (FilePath -> Action HscEnvEq )
360275loadSession dir = liftIO $ do
361276 cradleLoc <- memoIO $ \ v -> do
0 commit comments