From 228181817284070efe29f64e793a531224f135b3 Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Fri, 27 Nov 2020 11:55:48 +0800 Subject: [PATCH] Preserve the last empty comment line after eval plugin ```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 ``` --- plugins/default/src/Ide/Plugin/Eval.hs | 9 ++++++++- test/functional/Eval.hs | 2 ++ test/testdata/eval/T27.hs | 4 ++++ test/testdata/eval/T27.hs.expected | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/testdata/eval/T27.hs create mode 100644 test/testdata/eval/T27.hs.expected diff --git a/plugins/default/src/Ide/Plugin/Eval.hs b/plugins/default/src/Ide/Plugin/Eval.hs index 28a16f383e..e91396c03d 100644 --- a/plugins/default/src/Ide/Plugin/Eval.hs +++ b/plugins/default/src/Ide/Plugin/Eval.hs @@ -117,7 +117,14 @@ extractMatches = goSearch 0 . maybe [] T.lines r = Range p p' p = Position line 0 p' = Position (line + spliceLength) 0 - spliceLength = length (takeWhile looksLikeSplice (l : ll)) + spliceLines = takeWhile looksLikeSplice (l : ll) + -- Don't include the last line if it's an empty comment. + -- Do this to preserve spacing between consecutive splices + isEmptyComment = (== "--") + spliceLength = case spliceLines of + [] -> 0 + ls | isEmptyComment (last ls) -> length ls - 1 + | otherwise -> length ls provider :: CodeLensProvider provider lsp _state plId CodeLensParams {_textDocument} = response $ do diff --git a/test/functional/Eval.hs b/test/functional/Eval.hs index 7c5e6b62c0..78762599e4 100644 --- a/test/functional/Eval.hs +++ b/test/functional/Eval.hs @@ -91,6 +91,8 @@ tests = testGroup $ goldenTest "T25.hs" , testCase "local imports" $ goldenTest "T26.hs" + , testCase "Preserves one empty comment line after prompt" + $ goldenTest "T27.hs" ] goldenTest :: FilePath -> IO () diff --git a/test/testdata/eval/T27.hs b/test/testdata/eval/T27.hs new file mode 100644 index 0000000000..c1d68eba66 --- /dev/null +++ b/test/testdata/eval/T27.hs @@ -0,0 +1,4 @@ +module T27 where + +-- >>> () +-- diff --git a/test/testdata/eval/T27.hs.expected b/test/testdata/eval/T27.hs.expected new file mode 100644 index 0000000000..e931c55c29 --- /dev/null +++ b/test/testdata/eval/T27.hs.expected @@ -0,0 +1,5 @@ +module T27 where + +-- >>> () +-- () +--