1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 04:11:48 +03:00

Define reference to initial scope outside of for_ loop

This commit is contained in:
joshvera 2020-02-11 17:17:22 -05:00
parent 5339ee2e03
commit 02db8cfa8e

View File

@ -231,16 +231,17 @@ instance ToScopeGraph Py.GlobalStatement where scopeGraph = todo
instance ToScopeGraph Py.Integer where scopeGraph = mempty
instance ToScopeGraph Py.ImportStatement where
scopeGraph (Py.ImportStatement _ ((R1 (Py.DottedName _ names)) :| [])) = do
scopeGraph (Py.ImportStatement _ ((R1 (Py.DottedName _ names@((Py.Identifier ann name) :| _))) :| [])) = do
let toName (Py.Identifier _ name) = Name.name name
newEdge ScopeGraph.Import (toName <$> names)
let xs = zip (toList names) (tail $ toList names)
for_ xs $ \pair -> do
let referenceProps = Props.Reference ScopeGraph.Identifier ScopeGraph.Default (ann^.span_ :: Span)
newReference (Name.name name) referenceProps
let pairs = zip (toList names) (tail $ toList names)
for_ pairs $ \pair -> do
case pair of
(scopeIdentifier@(Py.Identifier ann _), referenceIdentifier@(Py.Identifier ann2 _)) -> do
let referenceProps = Props.Reference ScopeGraph.Identifier ScopeGraph.Default (ann^.span_ :: Span)
newReference (toName scopeIdentifier) referenceProps
(scopeIdentifier, referenceIdentifier@(Py.Identifier ann2 _)) -> do
withScope (toName scopeIdentifier) $ do
let referenceProps = Props.Reference ScopeGraph.Identifier ScopeGraph.Default (ann2^.span_ :: Span)
newReference (toName referenceIdentifier) referenceProps