From 1f7af3c8cb186a0ea05d3ffd5fb0fb22ab30cf4c Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Thu, 4 Jun 2020 16:34:58 +0400 Subject: [PATCH] Make infoOf always return an info --- tools/lsp/squirrel/src/AST/Scope.hs | 18 +++++++++--------- tools/lsp/squirrel/src/Tree.hs | 7 ++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/lsp/squirrel/src/AST/Scope.hs b/tools/lsp/squirrel/src/AST/Scope.hs index fdfc68bfa..98c0c26b5 100644 --- a/tools/lsp/squirrel/src/AST/Scope.hs +++ b/tools/lsp/squirrel/src/AST/Scope.hs @@ -45,8 +45,8 @@ newtype Env = Env deriving newtype (Semigroup, Monoid) data ScopedDecl = ScopedDecl - { _sdName :: Maybe (Pascal ()) - , _sdOrigin :: Maybe Range + { _sdName :: (Pascal ()) + , _sdOrigin :: Range , _sdBody :: Maybe Range , _sdType :: Maybe (Either (Pascal ()) Kind) } @@ -73,9 +73,9 @@ define = define_ method defType :: HasRange a => Pascal a -> Kind -> Pascal a -> ScopeM () defType name kind body = do define $ ScopedDecl - (Just (void name)) - (getRange <$> infoOf name) - (getRange <$> infoOf body) + (void name) + (getRange $ infoOf name) + (Just $ getRange $ infoOf body) (Just (Right kind)) def @@ -86,9 +86,9 @@ def -> ScopeM () def name ty body = do define $ ScopedDecl - (Just (void name)) - (getRange <$> infoOf name) - (getRange <$> do infoOf =<< body) + (void name) + (getRange $ infoOf name) + ((getRange . infoOf) <$> body) ((Left . void) <$> ty) instance UpdateOver ScopeM Contract (Pascal a) @@ -337,6 +337,6 @@ evalScopeM action = evalState action [Env []] testUpdate :: Pascal ASTInfo -> ScopeM (Pascal Scope) testUpdate = updateTree \_ -> do Env topmost <- gets head - let names = catMaybes $ _sdName <$> topmost + let names = _sdName <$> topmost let res = ppToText $ fsep $ map pp names return $ Scope res \ No newline at end of file diff --git a/tools/lsp/squirrel/src/Tree.hs b/tools/lsp/squirrel/src/Tree.hs index e4ec448d0..96bdb1f3d 100644 --- a/tools/lsp/squirrel/src/Tree.hs +++ b/tools/lsp/squirrel/src/Tree.hs @@ -121,11 +121,8 @@ mk :: (Functor f, Member f fs) => info -> f (Tree fs info) -> Tree fs info mk i fx = Tree $ Fix $ Compose $ Right $ Compose (i, inj $ fmap unTree fx) -- | Get info from the tree. -infoOf :: Tree fs info -> Maybe info -infoOf (Tree (Fix (Compose it))) = - either - (const Nothing) - (Just . fst . getCompose) it +infoOf :: Tree fs info -> info +infoOf = either eInfo (fst . getCompose) . getCompose . unFix . unTree instance Stubbed (Tree fs info) info where stub = Tree . Fix . Compose . Left