From c130887ebb707afe1450578449f56dfef975ed84 Mon Sep 17 00:00:00 2001 From: fwcd Date: Tue, 6 Aug 2024 16:58:10 +0200 Subject: [PATCH] Migrate ScopeState to record dot syntax --- src/Curry/LanguageServer/Utils/Lookup.hs | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Curry/LanguageServer/Utils/Lookup.hs b/src/Curry/LanguageServer/Utils/Lookup.hs index fdc6893..c69f29a 100644 --- a/src/Curry/LanguageServer/Utils/Lookup.hs +++ b/src/Curry/LanguageServer/Utils/Lookup.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, ViewPatterns #-} +{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, NoFieldSelectors, OverloadedRecordDot, ViewPatterns #-} -- | Position lookup in the AST. module Curry.LanguageServer.Utils.Lookup ( findQualIdentAtPos @@ -50,10 +50,10 @@ findTypeAtPos ast pos = elementAt pos $ typedSpanInfos ast -- | Finds all accessible identifiers at the given position, using the innermost shadowed one. findScopeAtPos :: CS.Module a -> J.Position -> Scope a -findScopeAtPos ast pos = sstMatchingEnv $ execState (collectScope ast) $ ScopeState - { sstCurrentEnv = [M.empty] - , sstMatchingEnv = M.empty - , sstPosition = pos +findScopeAtPos ast pos = (.matchingEnv) $ execState (collectScope ast) $ ScopeState + { currentEnv = [M.empty] + , matchingEnv = M.empty + , position = pos } withSpanInfo :: CSPI.HasSpanInfo a => a -> (a, CSPI.SpanInfo) @@ -73,31 +73,31 @@ flattenScopes = foldr M.union M.empty -- | Stores nested scopes and a cursor position. The head of the list is always the innermost collectScope. data ScopeState a = ScopeState - { sstCurrentEnv :: [Scope a] - , sstMatchingEnv :: Scope a - , sstPosition :: J.Position + { currentEnv :: [Scope a] + , matchingEnv :: Scope a + , position :: J.Position } type ScopeM a = State (ScopeState a) beginScope :: ScopeM a () -beginScope = modify $ \s -> s { sstCurrentEnv = M.empty : sstCurrentEnv s } +beginScope = modify $ \s -> s { currentEnv = M.empty : s.currentEnv } endScope :: ScopeM a () -endScope = modify $ \s -> s { sstCurrentEnv = let e = tail $ sstCurrentEnv s in if null e then error "Cannot end top-level scope!" else e } +endScope = modify $ \s -> s { currentEnv = let e = tail s.currentEnv in if null e then error "Cannot end top-level scope!" else e } withScope :: ScopeM a () -> ScopeM a () withScope x = beginScope >> x >> endScope bind :: CI.Ident -> Maybe a -> ScopeM a () bind i t = do - modify $ \s -> s { sstCurrentEnv = bindInScopes i t $ sstCurrentEnv s } + modify $ \s -> s { currentEnv = bindInScopes i t s.currentEnv } updateEnvs :: CSPI.HasSpanInfo e => e -> ScopeM a () updateEnvs (CSPI.getSpanInfo -> spi) = do - pos <- gets sstPosition + pos <- gets (.position) when (spi `containsPos` pos) $ - modify $ \s -> s { sstMatchingEnv = M.union (flattenScopes $ sstCurrentEnv s) $ sstMatchingEnv s } + modify $ \s -> s { matchingEnv = M.union (flattenScopes s.currentEnv) s.matchingEnv } class CollectScope e a where collectScope :: e -> ScopeM a ()