Skip to content

Commit d0fb85e

Browse files
authored
Preserve the last empty comment line after eval plugin (#631)
```haskell -- >>> foo -- -- >>> bar ``` After running the plugin on both prompts we end up with this: ```haskell -- >>> foo -- foo_output -- -- >>> bar -- bar_output ``` instead of ```haskell -- >>> foo -- foo_output -- >>> bar -- bar_output ```
1 parent 2e7c0ce commit d0fb85e

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

plugins/default/src/Ide/Plugin/Eval.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ extractMatches = goSearch 0 . maybe [] T.lines
117117
r = Range p p'
118118
p = Position line 0
119119
p' = Position (line + spliceLength) 0
120-
spliceLength = length (takeWhile looksLikeSplice (l : ll))
120+
spliceLines = takeWhile looksLikeSplice (l : ll)
121+
-- Don't include the last line if it's an empty comment.
122+
-- Do this to preserve spacing between consecutive splices
123+
isEmptyComment = (== "--")
124+
spliceLength = case spliceLines of
125+
[] -> 0
126+
ls | isEmptyComment (last ls) -> length ls - 1
127+
| otherwise -> length ls
121128

122129
provider :: CodeLensProvider
123130
provider lsp _state plId CodeLensParams {_textDocument} = response $ do

test/functional/Eval.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ tests = testGroup
9191
$ goldenTest "T25.hs"
9292
, testCase "local imports"
9393
$ goldenTest "T26.hs"
94+
, testCase "Preserves one empty comment line after prompt"
95+
$ goldenTest "T27.hs"
9496
]
9597

9698
goldenTest :: FilePath -> IO ()

test/testdata/eval/T27.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module T27 where
2+
3+
-- >>> ()
4+
--

test/testdata/eval/T27.hs.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module T27 where
2+
3+
-- >>> ()
4+
-- ()
5+
--

0 commit comments

Comments
 (0)