mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-02 08:53:07 +03:00
Final tweaks?
This commit is contained in:
parent
9527499f45
commit
5e4e87822e
26
exe/Main.hs
26
exe/Main.hs
@ -45,7 +45,8 @@ import Development.IDE.Plugin.Completions as Completions
|
|||||||
import Development.IDE.Plugin.CodeAction as CodeAction
|
import Development.IDE.Plugin.CodeAction as CodeAction
|
||||||
import qualified Language.Haskell.LSP.Core as LSP
|
import qualified Language.Haskell.LSP.Core as LSP
|
||||||
import Language.Haskell.LSP.Messages
|
import Language.Haskell.LSP.Messages
|
||||||
import Language.Haskell.LSP.Types (LspId(IdInt))
|
import Language.Haskell.LSP.Types
|
||||||
|
import Data.Aeson (ToJSON(toJSON))
|
||||||
import Development.IDE.LSP.LanguageServer
|
import Development.IDE.LSP.LanguageServer
|
||||||
import qualified System.Directory.Extra as IO
|
import qualified System.Directory.Extra as IO
|
||||||
import System.Environment
|
import System.Environment
|
||||||
@ -228,15 +229,16 @@ setNameCache nc hsc = hsc { hsc_NC = nc }
|
|||||||
|
|
||||||
loadSessionShake :: FilePath -> Action (FilePath -> Action (IdeResult HscEnvEq))
|
loadSessionShake :: FilePath -> Action (FilePath -> Action (IdeResult HscEnvEq))
|
||||||
loadSessionShake fp = do
|
loadSessionShake fp = do
|
||||||
ShakeExtras{logger} <- getShakeExtras
|
se <- getShakeExtras
|
||||||
res <- liftIO $ loadSession logger fp
|
IdeOptions{optTesting} <- getIdeOptions
|
||||||
|
res <- liftIO $ loadSession optTesting se fp
|
||||||
return (fmap liftIO res)
|
return (fmap liftIO res)
|
||||||
|
|
||||||
-- | This is the key function which implements multi-component support. All
|
-- | This is the key function which implements multi-component support. All
|
||||||
-- components mapping to the same hie.yaml file are mapped to the same
|
-- components mapping to the same hie.yaml file are mapped to the same
|
||||||
-- HscEnv which is updated as new components are discovered.
|
-- HscEnv which is updated as new components are discovered.
|
||||||
loadSession :: Logger -> FilePath -> IO (FilePath -> IO (IdeResult HscEnvEq))
|
loadSession :: Bool -> ShakeExtras -> FilePath -> IO (FilePath -> IO (IdeResult HscEnvEq))
|
||||||
loadSession logger dir = do
|
loadSession optTesting ShakeExtras{logger, eventer} dir = do
|
||||||
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
|
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
|
||||||
hscEnvs <- newVar Map.empty :: IO (Var HieMap)
|
hscEnvs <- newVar Map.empty :: IO (Var HieMap)
|
||||||
-- Mapping from a Filepath to HscEnv
|
-- Mapping from a Filepath to HscEnv
|
||||||
@ -262,7 +264,7 @@ loadSession logger dir = do
|
|||||||
hscEnv <- emptyHscEnv
|
hscEnv <- emptyHscEnv
|
||||||
(df, targets) <- evalGhcEnv hscEnv $
|
(df, targets) <- evalGhcEnv hscEnv $
|
||||||
setOptions opts (hsc_dflags hscEnv)
|
setOptions opts (hsc_dflags hscEnv)
|
||||||
dep_info <- getDependencyInfo (componentDependencies opts)
|
dep_info <- getDependencyInfo (componentDependencies opts ++ maybeToList hieYaml)
|
||||||
-- Now lookup to see whether we are combining with an existing HscEnv
|
-- Now lookup to see whether we are combining with an existing HscEnv
|
||||||
-- or making a new one. The lookup returns the HscEnv and a list of
|
-- or making a new one. The lookup returns the HscEnv and a list of
|
||||||
-- information about other components loaded into the HscEnv
|
-- information about other components loaded into the HscEnv
|
||||||
@ -344,6 +346,7 @@ loadSession logger dir = do
|
|||||||
|
|
||||||
let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq)
|
let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq)
|
||||||
consultCradle hieYaml cfp = do
|
consultCradle hieYaml cfp = do
|
||||||
|
when optTesting $ eventer $ notifyCradleLoaded cfp
|
||||||
logInfo logger $ T.pack ("Consulting the cradle for " <> show cfp)
|
logInfo logger $ T.pack ("Consulting the cradle for " <> show cfp)
|
||||||
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
|
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
|
||||||
eopts <- cradleToSessionOpts cradle cfp
|
eopts <- cradleToSessionOpts cradle cfp
|
||||||
@ -615,7 +618,7 @@ setOptions (ComponentOptions theOpts compRoot _) dflags = do
|
|||||||
setIgnoreInterfacePragmas $
|
setIgnoreInterfacePragmas $
|
||||||
setLinkerOptions $
|
setLinkerOptions $
|
||||||
disableOptimisation $
|
disableOptimisation $
|
||||||
makeDynFlagsAbsolute comptRoot dflags'
|
makeDynFlagsAbsolute compRoot dflags'
|
||||||
-- initPackages parses the -package flags and
|
-- initPackages parses the -package flags and
|
||||||
-- sets up the visibility for each component.
|
-- sets up the visibility for each component.
|
||||||
(final_df, _) <- liftIO $ initPackages dflags''
|
(final_df, _) <- liftIO $ initPackages dflags''
|
||||||
@ -655,6 +658,15 @@ getCacheDir prefix opts = IO.getXdgDirectory IO.XdgCache (cacheDir </> prefix ++
|
|||||||
cacheDir :: String
|
cacheDir :: String
|
||||||
cacheDir = "ghcide"
|
cacheDir = "ghcide"
|
||||||
|
|
||||||
|
notifyCradleLoaded :: FilePath -> FromServerMessage
|
||||||
|
notifyCradleLoaded fp =
|
||||||
|
NotCustomServer $
|
||||||
|
NotificationMessage "2.0" (CustomServerMethod cradleLoadedMethod) $
|
||||||
|
toJSON fp
|
||||||
|
|
||||||
|
cradleLoadedMethod :: T.Text
|
||||||
|
cradleLoadedMethod = "ghcide/cradle/loaded"
|
||||||
|
|
||||||
ghcVersionChecker :: IO VersionCheck
|
ghcVersionChecker :: IO VersionCheck
|
||||||
ghcVersionChecker = $$(makeGhcVersionChecker (pure <$> getLibdir))
|
ghcVersionChecker = $$(makeGhcVersionChecker (pure <$> getLibdir))
|
||||||
|
|
||||||
|
@ -306,8 +306,4 @@ getConArgs = GHC.getConDetails
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
getPackageName :: DynFlags -> Module.InstalledUnitId -> Maybe PackageName
|
getPackageName :: DynFlags -> Module.InstalledUnitId -> Maybe PackageName
|
||||||
#if MIN_GHC_API_VERSION(8,10,0)
|
|
||||||
getPackageName dfs i = getPackageName <$> lookupPackage dfs (DefUnitId i)
|
|
||||||
#else
|
|
||||||
getPackageName dfs i = packageName <$> lookupPackage dfs (Module.DefiniteUnitId (Module.DefUnitId i))
|
getPackageName dfs i = packageName <$> lookupPackage dfs (Module.DefiniteUnitId (Module.DefUnitId i))
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user