haskell / haskell-language-server

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

getLine in eval code lens causes connection got disposed #2913

Open michaelmesser opened 2 years ago

michaelmesser commented 2 years ago

Your environment

Which OS do you use:

MacOS Which LSP client (editor/plugin) do you use:

VS Code+vscode-haskell

Describe your project (alternative: link to the project):

resolver:
  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/7.yaml

packages:
- .

Steps to reproduce

{-
>>> getLine
-}

Run the Evaluate code lens

Expected behaviour

Not sure

Actual behaviour

{-
>>> getLine
"Content-Length: 191\r"
-}

VSCode shows error message: Connection got disposed.

Include debug information

xsebek commented 2 years ago

Hi @michaelmesser, this is a known limitation of the hls-eval-plugin.

My understanding of the plugin is that it runs in the same process as HLS, so you can not easily redirect its stdout/stderr. Redirecting stdin seems even trickier than output because it's not clear how you should interact with it from the editor.

If you want, we could use this Issue to discuss what should be the Expected behaviour. :slightly_smiling_face:


If you are looking for a workaround, you can get IO String with simple pure "My Input" or you can write your tested functions to accept String and separate the input/output handling. I hope that's helpful. :wink:

michaelpj commented 2 years ago

Maybe we could capture this limitation in the docs? We have a few "Known limitations" sections in the Features page.

xsebek commented 2 years ago

Actual behaviour

>>> getLine
"Content-Length: 191\r"

Btw. is the string stolen from the input sent to HLS and making it close the connection? :thinking:

@anka-213 pointed out in #1977 that HLS moves its stdout, maybe a similar thing is necessary for stdin here?

pepeiborra commented 2 years ago

@anka-213 pointed out in #1977 that HLS moves its stdout, maybe a similar thing is necessary for stdin here

Yes, this is right. The redirection is done in Development.IDE.Main