@@ -102,8 +102,8 @@ import Ide.Plugin.Eval.Code (Statement,
102102 execStmtCaptureResult ,
103103 propSetup ,
104104 resultRange ,
105- testCheck ,
106- testRanges )
105+ evalExprCheck ,
106+ evalExprRanges )
107107import Ide.Plugin.Eval.Config (EvalConfig (.. ),
108108 getEvalConfig )
109109import Ide.Plugin.Eval.GHC (addImport ,
@@ -134,8 +134,8 @@ codeAction recorder st plId CodeActionParams{_textDocument,_range} = do
134134 pure
135135 $ InL
136136 [ InL command
137- | (testRange , command) <- rangeCommands
138- , _range `isSubrangeOf` testRange
137+ | (evalExprRange , command) <- rangeCommands
138+ , _range `isSubrangeOf` evalExprRange
139139 ]
140140
141141{- | Code Lens provider
@@ -150,7 +150,7 @@ codeLens recorder st plId CodeLensParams{_textDocument} = do
150150 | (range, command) <- rangeCommands
151151 ]
152152
153- -- | Find every test in the document and pair its source range with the
153+ -- | Find every eval-expr in the document and pair its source range with the
154154-- 'Command' that evaluates it. Shared by the code action and code lens
155155-- providers.
156156mkRangeCommands :: Recorder (WithPriority Log ) -> IdeState -> PluginId -> TextDocumentIdentifier -> ExceptT PluginError (HandlerM Config ) [(Range , Command )]
@@ -168,14 +168,14 @@ mkRangeCommands recorder st plId textDocument =
168168 runActionE " eval.GetParsedModuleWithComments" st $ useWithStaleE GetEvalComments nfp
169169 dbg $ LogCodeLensComments comments
170170
171- -- Extract tests from source code
171+ -- Extract 'EvalExpr's from source code
172172 let Sections {.. } = commentsToSections isLHS comments
173- tests = testsBySection nonSetupSections
173+ evalExprs = evalExprsBySection nonSetupSections
174174 cmd = mkLspCommand plId evalCommandName " Evaluate=..." (Just [] )
175175 let rangeCommands =
176- [ (testRange , cmd')
177- | (section, ident, test ) <- tests
178- , let (testRange , resultRange) = testRanges test
176+ [ (evalExprRange , cmd')
177+ | (section, ident, evalExpr ) <- evalExprs
178+ , let (evalExprRange , resultRange) = evalExprRanges evalExpr
179179 args = EvalParams (setupSections ++ [section]) textDocument ident
180180 cmd' =
181181 (cmd :: Command )
@@ -187,9 +187,9 @@ mkRangeCommands recorder st plId textDocument =
187187 }
188188 ]
189189
190- perf " tests " $
191- dbg $ LogTests
192- (length tests )
190+ perf " evalExprs " $
191+ dbg $ LogEvalExprs
192+ (length evalExprs )
193193 (length nonSetupSections)
194194 (length setupSections)
195195 (length rangeCommands)
@@ -212,7 +212,7 @@ runEvalCmd recorder plId st mtoken EvalParams{..} =
212212 perf = timed (\ lbl duration -> dbg $ LogExecutionTime lbl duration)
213213 cmd :: ExceptT PluginError (HandlerM Config ) WorkspaceEdit
214214 cmd = do
215- let tests = map (\ (a,_,b) -> (a,b)) $ testsBySection sections
215+ let evalExprs = map (\ (a,_,b) -> (a,b)) $ evalExprsBySection sections
216216
217217 let TextDocumentIdentifier {_uri} = module_
218218 fp <- uriToFilePathE _uri
@@ -229,7 +229,7 @@ runEvalCmd recorder plId st mtoken EvalParams{..} =
229229 unqueueForEvaluation st nfp
230230 return [toKey IsEvaluating nfp]
231231 )
232- (initialiseSessionForEval (needsQuickCheck tests ) st nfp)
232+ (initialiseSessionForEval (needsQuickCheck evalExprs ) st nfp)
233233
234234 evalCfg <- liftIO $ runAction " eval: config" st $ getEvalConfig plId
235235
@@ -238,7 +238,7 @@ runEvalCmd recorder plId st mtoken EvalParams{..} =
238238 perf " edits" $
239239 liftIO $
240240 evalGhcEnv final_hscEnv $ do
241- runTests recorder evalCfg fp tests
241+ runEvalExprs recorder evalCfg fp evalExprs
242242
243243 let workspaceEditsMap = Map. singleton _uri (addFinalReturn mdlText edits)
244244 let workspaceEdits = WorkspaceEdit (Just workspaceEditsMap) Nothing Nothing
@@ -359,13 +359,13 @@ moduleText state uri = do
359359 toNormalizedUri uri
360360 pure $ Rope. toText contents
361361
362- -- | Flatten sections into their individual tests , tagging each with the index
362+ -- | Flatten sections into their individual 'EvalExpr's , tagging each with the index
363363-- ('EvalId') of its containing section.
364- testsBySection :: [Section ] -> [(Section , EvalId , Test )]
365- testsBySection sections =
366- [(section, ident, test )
364+ evalExprsBySection :: [Section ] -> [(Section , EvalId , EvalExpr )]
365+ evalExprsBySection sections =
366+ [(section, ident, evalExpr )
367367 | (ident, section) <- zip [0 .. ] sections
368- , test <- sectionTests section
368+ , evalExpr <- sectionEvalExprs section
369369 ]
370370
371371type TEnv = String
@@ -382,59 +382,59 @@ evalSetup = do
382382 context <- getContext
383383 setContext (IIDecl preludeAsP : IIDecl systemIO : IIDecl ghcIOHandle : context)
384384
385- -- | Evaluate every test and produce the 'TextEdit's that write the results
385+ -- | Evaluate every 'EvalExpr' and produce the 'TextEdit's that write the results
386386-- back into the document, prefixing/padding each result line as the section's
387387-- format requires.
388- runTests :: Recorder (WithPriority Log ) -> EvalConfig -> TEnv -> [(Section , Test )] -> Ghc [TextEdit ]
389- runTests recorder EvalConfig {.. } e tests = do
388+ runEvalExprs :: Recorder (WithPriority Log ) -> EvalConfig -> TEnv -> [(Section , EvalExpr )] -> Ghc [TextEdit ]
389+ runEvalExprs recorder EvalConfig {.. } e evalExprs = do
390390 df <- getInteractiveDynFlags
391391 evalSetup
392- when (hasQuickCheck df && needsQuickCheck tests ) $ void $ evals recorder True e df propSetup
392+ when (hasQuickCheck df && needsQuickCheck evalExprs ) $ void $ evals recorder True e df propSetup
393393
394- mapM (processTest e df) tests
394+ mapM (processEvalExpr e df) evalExprs
395395 where
396- processTest :: TEnv -> DynFlags -> (Section , Test ) -> Ghc TextEdit
397- processTest fp df (section, test ) = do
396+ processEvalExpr :: TEnv -> DynFlags -> (Section , EvalExpr ) -> Ghc TextEdit
397+ processEvalExpr fp df (section, evalExpr ) = do
398398 let dbg = logWith recorder Debug
399399 let pad = pad_ $ (if isLiterate fp then (" > " `T.append` ) else id ) $ padPrefix (sectionFormat section)
400- rs <- runTest e df test
401- dbg $ LogRunTestResults rs
400+ rs <- runEvalExpr e df evalExpr
401+ dbg $ LogRunEvalExprResults rs
402402
403- let checkedResult = testCheck eval_cfg_diff (section, test ) rs
403+ let checkedResult = evalExprCheck eval_cfg_diff (section, evalExpr ) rs
404404 let resultLines = concatMap T. lines checkedResult
405405
406- let edit = asEdit (sectionFormat section) test (map pad resultLines)
407- dbg $ LogRunTestEdits edit
406+ let edit = asEdit (sectionFormat section) evalExpr (map pad resultLines)
407+ dbg $ LogRunEvalExprEdits edit
408408 return edit
409409
410- -- runTest :: String -> DynFlags -> Loc Test -> Ghc [Text]
411- runTest _ df test
412- | not (hasQuickCheck df) && isProperty test =
410+ -- runEvalExpr :: String -> DynFlags -> Loc EvalExpr -> Ghc [Text]
411+ runEvalExpr _ df evalExpr
412+ | not (hasQuickCheck df) && isProperty evalExpr =
413413 return $
414414 singleLine
415- " Add QuickCheck to your cabal dependencies to run this test ."
416- runTest e df test = evals recorder (eval_cfg_exception && not (isProperty test )) e df (asStatements test )
417-
418- -- | Build the edit that replaces a test's old result with @resultLines@. For a
419- -- test that sits on the closing @-}@ line of a block comment, the result is
420- -- inserted before @-}@ on fresh lines; otherwise it simply overwrites the
421- -- existing result range.
422- asEdit :: Format -> Test -> [Text ] -> TextEdit
423- asEdit (MultiLine commRange) test resultLines
424- -- A test in a block comment, ending with @-\}@ without newline in-between.
425- | testRange test ^. L. end . L. line == commRange ^. L. end . L. line
415+ " Add QuickCheck to your cabal dependencies to run this property ."
416+ runEvalExpr e df evalExpr = evals recorder (eval_cfg_exception && not (isProperty evalExpr )) e df (asStatements evalExpr )
417+
418+ -- | Build the edit that replaces the old result of an 'EvalExpr' with
419+ -- @resultLines@. For an 'EvalExpr' that sits on the closing @-}@ line of a
420+ -- block comment, the result is inserted before @-}@ on fresh lines; otherwise
421+ -- it simply overwrites the existing result range.
422+ asEdit :: Format -> EvalExpr -> [Text ] -> TextEdit
423+ asEdit (MultiLine commRange) evalExpr resultLines
424+ -- An 'EvalExpr' in a block comment, ending with @-\}@ without newline in-between.
425+ | evalExprRange evalExpr ^. L. end . L. line == commRange ^. L. end . L. line
426426 =
427427 TextEdit
428428 (Range
429- (testRange test ^. L. end)
430- (resultRange test ^. L. end)
429+ (evalExprRange evalExpr ^. L. end)
430+ (resultRange evalExpr ^. L. end)
431431 )
432432 (" \n " <> T. unlines (resultLines <> [" -}" ]))
433- asEdit _ test resultLines =
434- TextEdit (resultRange test ) (T. unlines resultLines)
433+ asEdit _ evalExpr resultLines =
434+ TextEdit (resultRange evalExpr ) (T. unlines resultLines)
435435
436436{- |
437- The result of evaluating a test line can be:
437+ The result of evaluating an eval-expr line can be:
438438* a value
439439* nothing
440440* a (possibly multiline) error message
@@ -576,7 +576,7 @@ evals recorder mark_exception fp df stmts = do
576576 let opts = execOptions{execSourceFile = fp, execLineNumber = l}
577577 in execStmtCaptureResult recorder stmt opts
578578
579- needsQuickCheck :: [(Section , Test )] -> Bool
579+ needsQuickCheck :: [(Section , EvalExpr )] -> Bool
580580needsQuickCheck = any (isProperty . snd )
581581
582582hasQuickCheck :: DynFlags -> Bool
0 commit comments