haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Eval plugin: output difff when there's trailing newline #4410

Open jakio6 opened 3 weeks ago

jakio6 commented 3 weeks ago

Your environment

Which OS do you use? Linux

Which version of GHC do you use and how did you install it? 9.8.2, ghcup

How is your project built (alternative: link to the project)? single file

Which LSP client (editor/plugin) do you use? neovim builtin

Which version of HLS do you use and how did you install it? 2.7.0.0, ghcup

Have you configured HLS in any way (especially: a hie.yaml file)? no

Steps to reproduce

Evaluate twice

-- |
-- >>> import Prettyprinter
--
-- >>> pretty "foo"
--
-- >>> pretty "foo\n"
--
-- >>> pretty "foo\n\n"
--

Expected behaviour

No diff for the last two test.

Actual behaviour

First evaluate:

-- |
-- >>> import Prettyprinter
--
-- >>> pretty "foo"
-- foo
--
-- >>> pretty "foo\n"
-- foo
--
-- >>> pretty "foo\n\n"
-- foo
-- <BLANKLINE>
--

Second evaluate:

-- |
-- >>> import Prettyprinter
--
-- >>> pretty "foo"
-- foo
--
-- >>> pretty "foo\n"
-- WAS foo
-- NOW foo
--
-- >>> pretty "foo\n\n"
-- WAS foo
-- WAS <BLANKLINE>
-- NOW foo
-- <BLANKLINE>
--

Debug information

fendor commented 3 weeks ago

Hi, thank you for the bug report!

I feel like the reason why this is difficult to do correctly is that it is impossible to tell when the expected output ends... We would need a terminating character, or another identifier for multi line outputs. Or, we might want to forbid multi-line outputs altogether.

Maybe we can take inspiration from cabal-docspec and see how it behaves in this situation?

jakio6 commented 3 weeks ago

Append an extra <BLANKLINE> to the last two case would be enough to pass doctest.

jott8 commented 1 week ago

I'll try to work on this issue