1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

Declare parameters of a function with their own spans

This commit is contained in:
joshvera 2019-01-18 17:52:44 -05:00
parent 52afa47ca3
commit ca4db58d83

View File

@ -29,16 +29,19 @@ instance Diffable Function where
-- TODO: How should we represent function types, where applicable? -- TODO: How should we represent function types, where applicable?
instance Evaluatable Function where instance Evaluatable Function where
eval _ _ Function{..} = do eval eval _ Function{..} = do
name <- maybeM (throwNoNameError functionName) (declaredName functionName) name <- maybeM (throwNoNameError functionName) (declaredName functionName)
span <- ask @Span span <- ask @Span
associatedScope <- declareFunction name span ScopeGraph.Function associatedScope <- declareFunction name span ScopeGraph.Function
params <- withScope associatedScope . for functionParameters $ \paramNode -> do params <- withScope associatedScope . for functionParameters $ \paramNode -> do
param <- maybeM (throwNoNameError paramNode) (declaredName paramNode) param <- maybeM (throwNoNameError paramNode) (declaredName paramNode)
-- TODO: Come up with an easier way to fetch the child node span instead of evaling it.
_ <- eval paramNode
paramSpan <- get @Span
-- TODO: This might be a motivation for a typeclass for `declarationKind` since we -- TODO: This might be a motivation for a typeclass for `declarationKind` since we
-- sometimes create declarations for our children. -- sometimes create declarations for our children.
param <$ declare (Declaration param) Default span ScopeGraph.Parameter Nothing param <$ declare (Declaration param) Default paramSpan ScopeGraph.Parameter Nothing
addr <- lookupDeclaration (Declaration name) addr <- lookupDeclaration (Declaration name)
v <- function name params functionBody associatedScope v <- function name params functionBody associatedScope