@@ -38,11 +38,13 @@ import Control.Effect.Fresh
38
38
import Control.Effect.Reader
39
39
import Control.Lens
40
40
import Data.List.NonEmpty
41
+ import qualified Data.List.NonEmpty as NonEmpty
41
42
import Data.Map.Strict (Map )
42
43
import qualified Data.Map.Strict as Map
43
44
import qualified Data.Module as Module
44
45
import qualified Data.ScopeGraph as ScopeGraph
45
46
import Data.Semilattice.Lower
47
+ import qualified Data.Set as Set
46
48
import Data.Text (Text )
47
49
import GHC.Records
48
50
import qualified Scope.Reference as Reference
@@ -61,6 +63,7 @@ import qualified Control.Effect.ScopeGraph.Properties.Reference as Props
61
63
import qualified Control.Effect.ScopeGraph.Properties.Reference as Props.Reference
62
64
import Control.Effect.State
63
65
66
+ import qualified Algebra.Graph as Graph
64
67
import qualified Algebra.Graph.Class as Class
65
68
66
69
-- | Extract the 'Just' of a 'Maybe' in an 'Applicative' context or, given 'Nothing', run the provided action.
@@ -132,9 +135,16 @@ addDeclarations names = do
132
135
graph <- get @ (Stack. Graph Stack. Node )
133
136
CurrentScope current <- currentScope
134
137
135
- let graph' = foldr (\ (ann, name) graph ->
136
- graph -<< (Stack. declaration " reference" ) -<< (Stack. pushSymbol name)) mempty names
137
- put (Stack. simplify (Class. overlay (Stack. scope current >>- graph') graph))
138
+ let graph' = foldr (\ (_, name) graph ->
139
+ graph -<< (Stack. popSymbol " member" ) -<< (Stack. declaration name)) mempty (NonEmpty. init names)
140
+ graph'' = graph' >>- (Stack. declaration (snd $ NonEmpty. last names))
141
+ graph''' = foldr (\ (_, name) graph ->
142
+ graph -<< (Stack. pushSymbol " member" ) -<< (Stack. reference name)) mempty (NonEmpty. init $ NonEmpty. reverse names)
143
+ graph'''' = graph'' >>- graph''' >>- (Stack. reference (snd $ NonEmpty. head names))
144
+ currentEdges = Set. filter (\ (left, right) -> left == Stack. Scope current) (Stack. edgeSet graph)
145
+ rootNodes = Set. map snd currentEdges
146
+ graphh = foldMap (\ (left, right) -> Stack. removeEdge left right graph) currentEdges
147
+ put (Stack. simplify (Class. overlay (Stack. scope current >>- graph'''' >>- Class. vertex (Set. elemAt 0 rootNodes)) graphh))
138
148
139
149
-- | Takes an edge label and a list of names and inserts an import edge to a hole.
140
150
newEdge :: ScopeGraphEff sig m => ScopeGraph. EdgeLabel -> NonEmpty Name -> m ()
0 commit comments