1
1
mirror of https://github.com/github/semantic.git synced 2024-12-15 01:51:39 +03:00

Use insertScope.

This commit is contained in:
Rob Rix 2018-12-06 11:09:08 -05:00
parent 816205244c
commit b47e28f278

View File

@ -139,14 +139,14 @@ declare declaration ddata assocScope currentScope g@(ScopeGraph graph) = fromMay
-- | Add a reference to a declaration in the scope graph. -- | Add a reference to a declaration in the scope graph.
-- Returns the original scope graph if the declaration could not be found. -- Returns the original scope graph if the declaration could not be found.
reference :: Ord scope => Reference -> Declaration -> scope -> ScopeGraph scope -> ScopeGraph scope reference :: Ord scope => Reference -> Declaration -> scope -> ScopeGraph scope -> ScopeGraph scope
reference ref decl@Declaration{..} currentAddress g@(ScopeGraph graph) = fromMaybe g $ do reference ref decl@Declaration{..} currentAddress g = fromMaybe g $ do
-- Start from the current address -- Start from the current address
currentScope' <- lookupScope currentAddress g currentScope' <- lookupScope currentAddress g
-- Build a path up to the declaration -- Build a path up to the declaration
go currentScope' currentAddress id go currentScope' currentAddress id
where where
go currentScope address path go currentScope address path
= ScopeGraph . flip (Map.insert currentAddress) graph . modifyReferences currentScope . Map.insert ref . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g = flip (insertScope currentAddress) g . modifyReferences currentScope . Map.insert ref . path . DPath decl . snd <$> lookupDeclaration unDeclaration address g
<|> traverseEdges' Superclass <|> traverseEdges' Import <|> traverseEdges' Lexical <|> traverseEdges' Superclass <|> traverseEdges' Import <|> traverseEdges' Lexical
where traverseEdges' edge = linksOfScope address g >>= Map.lookup edge >>= traverseEdges path (go currentScope) edge where traverseEdges' edge = linksOfScope address g >>= Map.lookup edge >>= traverseEdges path (go currentScope) edge