1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 05:11:44 +03:00

Split the LoadError handling out into a separate function.

This commit is contained in:
Rob Rix 2018-05-06 16:35:04 -04:00
parent 0dedd68188
commit 136a9661d2
2 changed files with 15 additions and 8 deletions

View File

@ -3,6 +3,7 @@ module Analysis.Abstract.ImportGraph
( ImportGraph(..)
, renderImportGraph
, graphingTerms
, graphingLoadErrors
, graphingModules
, importGraphing
) where
@ -54,12 +55,10 @@ style = (defaultStyle vertexName)
edgeAttributes Variable{} Module{} = [ "color" := "blue" ]
edgeAttributes _ _ = []
graphingTerms :: forall location term value effects syntax ann a
. ( Element Syntax.Identifier syntax
graphingTerms :: ( Element Syntax.Identifier syntax
, Members '[ Reader (Environment (Located location) value)
, Reader ModuleInfo
, Reader PackageInfo
, Resumable (LoadError term)
, State (Environment (Located location) value)
, State (ImportGraph term)
] effects
@ -73,10 +72,18 @@ graphingTerms recur term@(In _ syntax) = do
moduleInclusion (Variable (unName name))
variableDefinition name
_ -> pure ()
resume
@(LoadError term)
(recur term)
(\ (LoadError name) -> moduleInclusion (Module (BC.pack name)) *> pure [])
(recur term)
graphingLoadErrors :: forall location term value effects a
. Members '[ Reader ModuleInfo
, Resumable (LoadError term)
, State (ImportGraph term)
] effects
=> SubtermAlgebra (Base term) term (Evaluator location term value effects a)
-> SubtermAlgebra (Base term) term (Evaluator location term value effects a)
graphingLoadErrors recur term = resume @(LoadError term)
(recur term)
(\ (LoadError name) -> moduleInclusion (Module (BC.pack name)) *> pure [])
graphingModules :: Members '[ Reader ModuleInfo
, Reader PackageInfo

View File

@ -108,7 +108,7 @@ graphImports :: ( Show ann
)
=> Package (Term (Sum syntax) ann)
-> Eff effs (ImportGraph (Term (Sum syntax) ann))
graphImports package = analyze importGraphAnalysis (evaluatePackageWith graphingModules graphingTerms package) >>= extractGraph
graphImports package = analyze importGraphAnalysis (evaluatePackageWith graphingModules (graphingLoadErrors . graphingTerms) package) >>= extractGraph
where
extractGraph result = case result of
(Right (Right ((_, graph), _)), _) -> pure graph