Skip to content

Commit c3b0b37

Browse files
mattapetPeter Mattasoulomoon
authored
hls-eval-plugin: Replicate #4139 (#4140)
* main function eval bug * hls-eval-plugin: set ghci backend for evaluation * Fixes #4139 * bench: add hls-eval-plugin experiments --------- Co-authored-by: Peter Matta <[email protected]> Co-authored-by: soulomoon <[email protected]>
1 parent b377058 commit c3b0b37

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

bench/config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ experiments:
106106
- "code actions after cradle edit"
107107
- "documentSymbols after edit"
108108
- "hole fit suggestions"
109+
- "eval execute single-line code lens"
110+
- "eval execute multi-line code lens"
109111

110112
# An ordered list of versions to analyze
111113
versions:

ghcide-bench/src/Experiments.hs

+58-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ experiments =
241241
benchWithSetup
242242
"hole fit suggestions"
243243
( mapM_ $ \DocumentPositions{..} -> do
244-
let edit =TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
244+
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
245245
.+ #rangeLength .== Nothing
246246
.+ #text .== t
247247
bottom = Position maxBound 0
@@ -266,6 +266,63 @@ experiments =
266266
case requireDiagnostic diags (DiagnosticSeverity_Error, (fromIntegral bottom, 8), "Found hole", Nothing) of
267267
Nothing -> pure True
268268
Just _err -> pure False
269+
),
270+
---------------------------------------------------------------------------------------
271+
benchWithSetup
272+
"eval execute single-line code lens"
273+
( mapM_ $ \DocumentPositions{..} -> do
274+
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
275+
.+ #rangeLength .== Nothing
276+
.+ #text .== t
277+
bottom = Position maxBound 0
278+
t = T.unlines
279+
[ ""
280+
, "-- >>> 1 + 2"
281+
]
282+
changeDoc doc [edit]
283+
)
284+
( \docs -> do
285+
not . null <$> forM docs (\DocumentPositions{..} -> do
286+
lenses <- getCodeLenses doc
287+
forM_ lenses $ \case
288+
CodeLens { _command = Just cmd } -> do
289+
executeCommand cmd
290+
waitForProgressStart
291+
waitForProgressDone
292+
_ -> return ()
293+
)
294+
),
295+
---------------------------------------------------------------------------------------
296+
benchWithSetup
297+
"eval execute multi-line code lens"
298+
( mapM_ $ \DocumentPositions{..} -> do
299+
let edit = TextDocumentContentChangeEvent $ InL $ #range .== Range bottom bottom
300+
.+ #rangeLength .== Nothing
301+
.+ #text .== t
302+
bottom = Position maxBound 0
303+
t = T.unlines
304+
[ ""
305+
, "data T = A | B | C | D"
306+
, " deriving (Show, Eq, Ord, Bounded, Enum)"
307+
, ""
308+
, "{-"
309+
, ">>> import Data.List (nub)"
310+
, ">>> xs = ([minBound..maxBound] ++ [minBound..maxBound] :: [T])"
311+
, ">>> nub xs"
312+
, "-}"
313+
]
314+
changeDoc doc [edit]
315+
)
316+
( \docs -> do
317+
not . null <$> forM docs (\DocumentPositions{..} -> do
318+
lenses <- getCodeLenses doc
319+
forM_ lenses $ \case
320+
CodeLens { _command = Just cmd } -> do
321+
executeCommand cmd
322+
waitForProgressStart
323+
waitForProgressDone
324+
_ -> return ()
325+
)
269326
)
270327
]
271328
where hasDefinitions (InL (Definition (InL _))) = True

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ initialiseSessionForEval needs_quickcheck st nfp = do
277277
. flip xopt_unset LangExt.MonomorphismRestriction
278278
. flip gopt_set Opt_ImplicitImportQualified
279279
. flip gopt_unset Opt_DiagnosticsShowCaret
280+
. setBackend ghciBackend
280281
$ (ms_hspp_opts ms) {
281282
useColor = Never
282283
, canUseColor = False }

plugins/hls-eval-plugin/test/Main.hs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ tests =
8888
, goldenWithEval "Reports an error for an incorrect type with :kind" "T13" "hs"
8989
, goldenWithEval' "Returns a fully-instantiated type for :type" "T14" "hs" (if ghcVersion >= GHC98 then "ghc98.expected" else "expected") -- See https://gitlab.haskell.org/ghc/ghc/-/issues/24069
9090
, knownBrokenForGhcVersions [GHC92, GHC94, GHC96, GHC98] "type +v does not work anymore with 9.2" $ goldenWithEval "Returns an uninstantiated type for :type +v, admitting multiple whitespaces around arguments" "T15" "hs"
91+
, goldenWithEval "Doesn't break in module containing main function" "T4139" "hs"
9192
, goldenWithEval "Returns defaulted type for :type +d, admitting multiple whitespaces around arguments" "T16" "hs"
9293
, goldenWithEval ":type reports an error when given with unknown +x option" "T17" "hs"
9394
, goldenWithEval "Reports an error when given with unknown command" "T18" "hs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module T4139 where
2+
3+
-- >>> 'x'
4+
-- 'x'
5+
6+
main :: IO ()
7+
main = putStrLn "Hello World!"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module T4139 where
2+
3+
-- >>> 'x'
4+
5+
main :: IO ()
6+
main = putStrLn "Hello World!"

0 commit comments

Comments
 (0)