Skip to content

Commit 6201d94

Browse files
committed
Remove onceIO
1 parent 401cdef commit 6201d94

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

.github/workflows/bench.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- '**'
7+
push:
78

89
jobs:
910
pre_job:

ghcide/src/Development/IDE/Plugin/CodeAction/Args.hs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,25 @@ runGhcideCodeAction :: LSP.MonadLsp Config m => IdeState -> MessageParams TextDo
5454
runGhcideCodeAction state (CodeActionParams _ _ (TextDocumentIdentifier uri) _range CodeActionContext {_diagnostics = List diags}) codeAction = do
5555
let mbFile = toNormalizedFilePath' <$> uriToFilePath uri
5656
runRule key = runAction ("GhcideCodeActions." <> show key) state $ runMaybeT $ MaybeT (pure mbFile) >>= MaybeT . use key
57-
caaExportsMap <-
58-
onceIO $
59-
runRule GhcSession >>= \case
60-
Just env -> do
61-
pkgExports <- envPackageExports env
62-
localExports <- readVar (exportsMap $ shakeExtras state)
63-
pure $ localExports <> pkgExports
64-
_ -> pure mempty
65-
caaIdeOptions <- onceIO $ runAction "GhcideCodeActions.getIdeOptions" state getIdeOptions
66-
caaParsedModule <- onceIO $ runRule GetParsedModule
67-
caaContents <-
68-
onceIO $
69-
runRule GetFileContents >>= \case
70-
Just (_, txt) -> pure txt
71-
_ -> pure Nothing
72-
caaDf <- onceIO $ fmap (ms_hspp_opts . pm_mod_summary) <$> caaParsedModule
73-
caaAnnSource <- onceIO $ runRule GetAnnotatedParsedSource
74-
caaTmr <- onceIO $ runRule TypeCheck
75-
caaHar <- onceIO $ runRule GetHieAst
76-
caaBindings <- onceIO $ runRule GetBindings
77-
caaGblSigs <- onceIO $ runRule GetGlobalBindingTypeSigs
57+
caaExportsMap =
58+
runRule GhcSession >>= \case
59+
Just env -> do
60+
pkgExports <- envPackageExports env
61+
localExports <- readVar (exportsMap $ shakeExtras state)
62+
pure $ localExports <> pkgExports
63+
_ -> pure mempty
64+
caaIdeOptions = runAction "GhcideCodeActions.getIdeOptions" state getIdeOptions
65+
caaParsedModule = runRule GetParsedModule
66+
caaContents =
67+
runRule GetFileContents >>= \case
68+
Just (_, txt) -> pure txt
69+
_ -> pure Nothing
70+
caaDf = fmap (ms_hspp_opts . pm_mod_summary) <$> caaParsedModule
71+
caaAnnSource = runRule GetAnnotatedParsedSource
72+
caaTmr = runRule TypeCheck
73+
caaHar = runRule GetHieAst
74+
caaBindings = runRule GetBindings
75+
caaGblSigs = runRule GetGlobalBindingTypeSigs
7876
liftIO $
7977
concat
8078
<$> sequence
@@ -146,15 +144,6 @@ data CodeActionArgs = CodeActionArgs
146144
caaDiagnostic :: Diagnostic
147145
}
148146

149-
-- | There's no concurrency in each provider,
150-
-- so we don't need to be thread-safe here
151-
onceIO :: MonadIO m => IO a -> m (IO a)
152-
onceIO io = do
153-
var <- liftIO $ newIORef Nothing
154-
pure $
155-
readIORef var >>= \case
156-
Just x -> pure x
157-
_ -> io >>= \x -> writeIORef' var (Just x) >> pure x
158147

159148
-------------------------------------------------------------------------------------------------
160149

0 commit comments

Comments
 (0)