Haskell在vscode中(使用WSL2),断点没有被触发。

huangapple go评论129阅读模式
英文:

Haskell in vscode (with WSL2), breakpoints not being hit

问题

我想开始学习Haskell,而VSCode似乎是一个不错的集成开发环境。我尝试进行设置。

我尝试了以下步骤:

我进入了WSL2(Ubuntu 20.04.6)中我想要工作的目录,并从那里执行了code .。这将在给定的文件夹中打开VSCode,然后我使用以下命令创建了一个Haskell项目:

  1. stack new my-project
  2. cd my-project
  3. stack setup

然后我使用stack build构建了项目。

接下来,我下载了扩展Haskell语言支持
然后我下载了扩展Haskell GHCi Debug Adapter Phoityne,并按照以下说明执行:

  1. stack install haskell-dap ghci-dap haskell-debug-adapter

最后,我在VSCode的Run and Debug选项卡下,点击create a launch.json file并选择haskell-debug-adapter。这将在*.vscode文件夹下创建launch.json*文件。

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "type": "ghc",
  6. "request": "launch",
  7. "name": "haskell(stack)",
  8. "internalConsoleOptions": "openOnSessionStart",
  9. "workspace": "${workspaceFolder}",
  10. "startup": "${workspaceFolder}/test/Spec.hs",
  11. "startupFunc": "",
  12. "startupArgs": "",
  13. "stopOnEntry": false,
  14. "mainArgs": "",
  15. "ghciPrompt": "H>>= ",
  16. "ghciInitialPrompt": "> ",
  17. "ghciCmd": "stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is TARGET",
  18. "ghciEnv": {},
  19. "logFile": "${workspaceFolder}/.vscode/phoityne.log",
  20. "logLevel": "WARNING",
  21. "forceInspect": false
  22. },
  23. {
  24. "type": "ghc",
  25. "request": "launch",
  26. "name": "haskell(cabal)",
  27. "internalConsoleOptions": "openOnSessionStart",
  28. "workspace": "${workspaceFolder}",
  29. "startup": "${workspaceFolder}/app/Main.hs",
  30. "startupFunc": "",
  31. "startupArgs": "",
  32. "stopOnEntry": false,
  33. "mainArgs": "",
  34. "ghciPrompt": "H>>= ",
  35. "ghciInitialPrompt": "> ",
  36. "ghciCmd": "cabal repl -w ghci-dap --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl",
  37. "ghciEnv": {},
  38. "logFile": "${workspaceFolder}/.vscode/phoityne.log",
  39. "logLevel": "WARNING",
  40. "forceInspect": false
  41. }
  42. ]
  43. }

从这个文件中看,似乎{workspaceFolder}/test/Spec.hs是启动的入口点。这个文件包含:

  1. main :: IO ()
  2. main = putStrLn "Test suite not yet implemented"

我在这两行上设置了断点,然后点击了Haskell(stack)配置的绿色播放按钮。

但是,这似乎没有任何作用。它只加载了几秒钟,终端上没有打印任何内容,断点也没有触发。有人知道我做错了什么吗?

英文:

I would like to start learning haskell and it seems vscode would be a decent IDE for this. I tried to set it up.

I tried the following :

I went into WSL2(ubuntu 20.04.6) in the directory I would like to work, and executed code . from there. This opens vscode at the given folder and then I created a haskell project using

  1. stack new my-project
  2. cd my-project
  3. stack setup

Then I build the project using stack build.

Next I donwload the extension haskell language support.
Next I download the extension haskell GHCi Debug Adapter Phoityne and follow the instructions by doing

  1. stack install haskell-dap ghci-dap haskell-debug-adapter

Finally I go under the Run and Debug tab in vscode, I click on create a launch.json file and and choose haskell-debug-adapter. This creates the launch.json file under .vscode folder

  1. {
  2. // Use IntelliSense to learn about possible attributes.
  3. // Hover to view descriptions of existing attributes.
  4. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  5. "version": "0.2.0",
  6. "configurations": [
  7. {
  8. "type": "ghc",
  9. "request": "launch",
  10. "name": "haskell(stack)",
  11. "internalConsoleOptions": "openOnSessionStart",
  12. "workspace": "${workspaceFolder}",
  13. "startup": "${workspaceFolder}/test/Spec.hs",
  14. "startupFunc": "",
  15. "startupArgs": "",
  16. "stopOnEntry": false,
  17. "mainArgs": "",
  18. "ghciPrompt": "H>>= ",
  19. "ghciInitialPrompt": "> ",
  20. "ghciCmd": "stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is TARGET",
  21. "ghciEnv": {},
  22. "logFile": "${workspaceFolder}/.vscode/phoityne.log",
  23. "logLevel": "WARNING",
  24. "forceInspect": false
  25. },
  26. {
  27. "type": "ghc",
  28. "request": "launch",
  29. "name": "haskell(cabal)",
  30. "internalConsoleOptions": "openOnSessionStart",
  31. "workspace": "${workspaceFolder}",
  32. "startup": "${workspaceFolder}/app/Main.hs",
  33. "startupFunc": "",
  34. "startupArgs": "",
  35. "stopOnEntry": false,
  36. "mainArgs": "",
  37. "ghciPrompt": "H>>= ",
  38. "ghciInitialPrompt": "> ",
  39. "ghciCmd": "cabal repl -w ghci-dap --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl",
  40. "ghciEnv": {},
  41. "logFile": "${workspaceFolder}/.vscode/phoityne.log",
  42. "logLevel": "WARNING",
  43. "forceInspect": false
  44. }
  45. ]
  46. }

It seems from this file that

{workspaceFolder}/test/Spec.hs is the entry point of the launch. This file contains

  1. main :: IO ()
  2. main = putStrLn "Test suite not yet implemented"

I put a breakpoint on both these lines and then click on the green play button for the haskell (stack) configuration.

However, this doesn't do nothing. It just loads for a few seconds and nothing is printed on the terminal and no breakpoints is hit. Does anyone has an idea what I am doing wrong?

答案1

得分: 2

认为我成功复制了你的问题。 当你运行了:

  1. stack install haskell-dap ghci-dap haskell-debug-adapter

它应该已经将两个程序ghci-daphaskell-debug-adapter安装到一个目录中,很可能是~/.local/bin。 请检查这些程序是否存在以及该目录是否在你的路径中,具体来说,你可以在VSCode终端窗口中启动ghci-dap --versionhaskell-debug-adapter --version吗?

我发现如果这些程序不在我的路径中,我会遇到与你相同的问题——在绿色调试箭头下出现短暂的“等待”动画,然后什么都没有。

英文:

I think I was able to duplicate your problem. When you ran:

  1. stack install haskell-dap ghci-dap haskell-debug-adapter

it should have installed two programs ghci-dap and haskell-debug-adapter into a directory, most likely ~/.local/bin. Check that those programs are there and that that directory is in your path, specifically that you can launch ghci-dap --version and haskell-debug-adapter --version from the terminal Window within VSCode.

I found that if those programs weren't in my path, I experienced the same problem as you -- a brief "waiting" animation under the green debug arrow, and nothing else.

huangapple
  • 本文由 发表于 2023年7月31日 22:38:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804669.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定