mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-16 22:52:41 +03:00
Add useNoFile helpers matching defineNoFile (#2126)
This commit is contained in:
parent
edaeac7a32
commit
2d637aa488
@ -57,7 +57,7 @@ ofInterestRules = do
|
|||||||
|
|
||||||
|
|
||||||
getFilesOfInterest :: Action (Set NormalizedFilePath)
|
getFilesOfInterest :: Action (Set NormalizedFilePath)
|
||||||
getFilesOfInterest = use_ GetFilesOfInterest ""
|
getFilesOfInterest = useNoFile_ GetFilesOfInterest
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ module Development.IDE.Core.Rules(
|
|||||||
priorityTypeCheck,
|
priorityTypeCheck,
|
||||||
priorityGenerateCore,
|
priorityGenerateCore,
|
||||||
priorityFilesOfInterest,
|
priorityFilesOfInterest,
|
||||||
runAction, useE, usesE,
|
runAction, useE, useNoFileE, usesE,
|
||||||
toIdeResult, defineNoFile,
|
toIdeResult, defineNoFile,
|
||||||
mainRule,
|
mainRule,
|
||||||
getGhcCore,
|
getGhcCore,
|
||||||
@ -68,6 +68,9 @@ toIdeResult = either (, Nothing) (([],) . Just)
|
|||||||
useE :: IdeRule k v => k -> NormalizedFilePath -> MaybeT Action v
|
useE :: IdeRule k v => k -> NormalizedFilePath -> MaybeT Action v
|
||||||
useE k = MaybeT . use k
|
useE k = MaybeT . use k
|
||||||
|
|
||||||
|
useNoFileE :: IdeRule k v => k -> MaybeT Action v
|
||||||
|
useNoFileE k = useE k ""
|
||||||
|
|
||||||
usesE :: IdeRule k v => k -> [NormalizedFilePath] -> MaybeT Action [v]
|
usesE :: IdeRule k v => k -> [NormalizedFilePath] -> MaybeT Action [v]
|
||||||
usesE k = MaybeT . fmap sequence . uses k
|
usesE k = MaybeT . fmap sequence . uses k
|
||||||
|
|
||||||
@ -108,9 +111,9 @@ getAtPoint file pos = fmap join $ runMaybeT $ do
|
|||||||
getDefinition :: NormalizedFilePath -> Position -> Action (Maybe Location)
|
getDefinition :: NormalizedFilePath -> Position -> Action (Maybe Location)
|
||||||
getDefinition file pos = fmap join $ runMaybeT $ do
|
getDefinition file pos = fmap join $ runMaybeT $ do
|
||||||
spans <- useE GetSpanInfo file
|
spans <- useE GetSpanInfo file
|
||||||
pkgState <- useE GhcSession ""
|
pkgState <- useNoFileE GhcSession
|
||||||
opts <- lift getIdeOptions
|
opts <- lift getIdeOptions
|
||||||
let getHieFile x = use (GetHieFile x) ""
|
let getHieFile x = useNoFile (GetHieFile x)
|
||||||
lift $ AtPoint.gotoDefinition getHieFile opts pkgState spans pos
|
lift $ AtPoint.gotoDefinition getHieFile opts pkgState spans pos
|
||||||
|
|
||||||
-- | Parse the contents of a daml file.
|
-- | Parse the contents of a daml file.
|
||||||
@ -135,7 +138,7 @@ getParsedModuleRule :: Rules ()
|
|||||||
getParsedModuleRule =
|
getParsedModuleRule =
|
||||||
define $ \GetParsedModule file -> do
|
define $ \GetParsedModule file -> do
|
||||||
(_, contents) <- getFileContents file
|
(_, contents) <- getFileContents file
|
||||||
packageState <- use_ GhcSession ""
|
packageState <- useNoFile_ GhcSession
|
||||||
opt <- getIdeOptions
|
opt <- getIdeOptions
|
||||||
liftIO $ Compile.parseModule opt packageState (fromNormalizedFilePath file) contents
|
liftIO $ Compile.parseModule opt packageState (fromNormalizedFilePath file) contents
|
||||||
|
|
||||||
@ -145,7 +148,7 @@ getLocatedImportsRule =
|
|||||||
pm <- use_ GetParsedModule file
|
pm <- use_ GetParsedModule file
|
||||||
let ms = pm_mod_summary pm
|
let ms = pm_mod_summary pm
|
||||||
let imports = ms_textual_imps ms
|
let imports = ms_textual_imps ms
|
||||||
env <- use_ GhcSession ""
|
env <- useNoFile_ GhcSession
|
||||||
let dflags = Compile.addRelativeImport pm $ hsc_dflags env
|
let dflags = Compile.addRelativeImport pm $ hsc_dflags env
|
||||||
opt <- getIdeOptions
|
opt <- getIdeOptions
|
||||||
xs <- forM imports $ \(mbPkgName, modName) ->
|
xs <- forM imports $ \(mbPkgName, modName) ->
|
||||||
@ -167,7 +170,7 @@ rawDependencyInformation f = go (Set.singleton f) Map.empty Map.empty
|
|||||||
let modGraph' = Map.insert f (Left ModuleParseError) modGraph
|
let modGraph' = Map.insert f (Left ModuleParseError) modGraph
|
||||||
in go fs modGraph' pkgs
|
in go fs modGraph' pkgs
|
||||||
Just imports -> do
|
Just imports -> do
|
||||||
packageState <- lift $ use_ GhcSession ""
|
packageState <- lift $ useNoFile_ GhcSession
|
||||||
modOrPkgImports <- forM imports $ \imp -> do
|
modOrPkgImports <- forM imports $ \imp -> do
|
||||||
case imp of
|
case imp of
|
||||||
(_modName, Just (PackageImport pkg)) -> do
|
(_modName, Just (PackageImport pkg)) -> do
|
||||||
@ -233,7 +236,7 @@ getSpanInfoRule =
|
|||||||
define $ \GetSpanInfo file -> do
|
define $ \GetSpanInfo file -> do
|
||||||
tc <- use_ TypeCheck file
|
tc <- use_ TypeCheck file
|
||||||
imports <- use_ GetLocatedImports file
|
imports <- use_ GetLocatedImports file
|
||||||
packageState <- use_ GhcSession ""
|
packageState <- useNoFile_ GhcSession
|
||||||
x <- liftIO $ Compile.getSrcSpanInfos packageState (fileImports imports) tc
|
x <- liftIO $ Compile.getSrcSpanInfos packageState (fileImports imports) tc
|
||||||
return ([], Just x)
|
return ([], Just x)
|
||||||
|
|
||||||
@ -245,7 +248,7 @@ typeCheckRule =
|
|||||||
deps <- use_ GetDependencies file
|
deps <- use_ GetDependencies file
|
||||||
tms <- uses_ TypeCheck (transitiveModuleDeps deps)
|
tms <- uses_ TypeCheck (transitiveModuleDeps deps)
|
||||||
setPriority priorityTypeCheck
|
setPriority priorityTypeCheck
|
||||||
packageState <- use_ GhcSession ""
|
packageState <- useNoFile_ GhcSession
|
||||||
opt <- getIdeOptions
|
opt <- getIdeOptions
|
||||||
liftIO $ Compile.typecheckModule opt packageState tms pm
|
liftIO $ Compile.typecheckModule opt packageState tms pm
|
||||||
|
|
||||||
@ -256,7 +259,7 @@ generateCoreRule =
|
|||||||
deps <- use_ GetDependencies file
|
deps <- use_ GetDependencies file
|
||||||
(tm:tms) <- uses_ TypeCheck (file:transitiveModuleDeps deps)
|
(tm:tms) <- uses_ TypeCheck (file:transitiveModuleDeps deps)
|
||||||
setPriority priorityGenerateCore
|
setPriority priorityGenerateCore
|
||||||
packageState <- use_ GhcSession ""
|
packageState <- useNoFile_ GhcSession
|
||||||
liftIO $ Compile.compileModule packageState tms tm
|
liftIO $ Compile.compileModule packageState tms tm
|
||||||
|
|
||||||
loadGhcSession :: Rules ()
|
loadGhcSession :: Rules ()
|
||||||
|
@ -28,8 +28,8 @@ module Development.IDE.Core.Shake(
|
|||||||
shakeRun,
|
shakeRun,
|
||||||
shakeProfile,
|
shakeProfile,
|
||||||
useStale,
|
useStale,
|
||||||
use, uses,
|
use, useNoFile, uses,
|
||||||
use_, uses_,
|
use_, useNoFile_, uses_,
|
||||||
define, defineEarlyCutoff,
|
define, defineEarlyCutoff,
|
||||||
getDiagnostics, unsafeClearDiagnostics,
|
getDiagnostics, unsafeClearDiagnostics,
|
||||||
IsIdeGlobal, addIdeGlobal, getIdeGlobalState, getIdeGlobalAction,
|
IsIdeGlobal, addIdeGlobal, getIdeGlobalState, getIdeGlobalAction,
|
||||||
@ -335,9 +335,15 @@ use :: IdeRule k v
|
|||||||
=> k -> NormalizedFilePath -> Action (Maybe v)
|
=> k -> NormalizedFilePath -> Action (Maybe v)
|
||||||
use key file = head <$> uses key [file]
|
use key file = head <$> uses key [file]
|
||||||
|
|
||||||
|
useNoFile :: IdeRule k v => k -> Action (Maybe v)
|
||||||
|
useNoFile key = use key ""
|
||||||
|
|
||||||
use_ :: IdeRule k v => k -> NormalizedFilePath -> Action v
|
use_ :: IdeRule k v => k -> NormalizedFilePath -> Action v
|
||||||
use_ key file = head <$> uses_ key [file]
|
use_ key file = head <$> uses_ key [file]
|
||||||
|
|
||||||
|
useNoFile_ :: IdeRule k v => k -> Action v
|
||||||
|
useNoFile_ key = use_ key ""
|
||||||
|
|
||||||
uses_ :: IdeRule k v => k -> [NormalizedFilePath] -> Action [v]
|
uses_ :: IdeRule k v => k -> [NormalizedFilePath] -> Action [v]
|
||||||
uses_ key files = do
|
uses_ key files = do
|
||||||
res <- uses key files
|
res <- uses key files
|
||||||
|
Loading…
Reference in New Issue
Block a user