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

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

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

问题

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

我尝试了以下步骤:

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

stack new my-project
cd my-project
stack setup

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

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

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

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

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "ghc",
            "request": "launch",
            "name": "haskell(stack)",
            "internalConsoleOptions": "openOnSessionStart",
            "workspace": "${workspaceFolder}",
            "startup": "${workspaceFolder}/test/Spec.hs",
            "startupFunc": "",
            "startupArgs": "",
            "stopOnEntry": false,
            "mainArgs": "",
            "ghciPrompt": "H>>= ",
            "ghciInitialPrompt": "> ",
            "ghciCmd": "stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is TARGET",
            "ghciEnv": {},
            "logFile": "${workspaceFolder}/.vscode/phoityne.log",
            "logLevel": "WARNING",
            "forceInspect": false
        },
        {
            "type": "ghc",
            "request": "launch",
            "name": "haskell(cabal)",
            "internalConsoleOptions": "openOnSessionStart",
            "workspace": "${workspaceFolder}",
            "startup": "${workspaceFolder}/app/Main.hs",
            "startupFunc": "",
            "startupArgs": "",
            "stopOnEntry": false,
            "mainArgs": "",
            "ghciPrompt": "H>>= ",
            "ghciInitialPrompt": "> ",
            "ghciCmd": "cabal repl -w ghci-dap --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl",
            "ghciEnv": {},
            "logFile": "${workspaceFolder}/.vscode/phoityne.log",
            "logLevel": "WARNING",
            "forceInspect": false
        }
    ]
}

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

main :: IO ()
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

stack new my-project
cd my-project
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

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

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "ghc",
            "request": "launch",
            "name": "haskell(stack)",
            "internalConsoleOptions": "openOnSessionStart",
            "workspace": "${workspaceFolder}",
            "startup": "${workspaceFolder}/test/Spec.hs",
            "startupFunc": "",
            "startupArgs": "",
            "stopOnEntry": false,
            "mainArgs": "",
            "ghciPrompt": "H>>= ",
            "ghciInitialPrompt": "> ",
            "ghciCmd": "stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is TARGET",
            "ghciEnv": {},
            "logFile": "${workspaceFolder}/.vscode/phoityne.log",
            "logLevel": "WARNING",
            "forceInspect": false
        },
        {
            "type": "ghc",
            "request": "launch",
            "name": "haskell(cabal)",
            "internalConsoleOptions": "openOnSessionStart",
            "workspace": "${workspaceFolder}",
            "startup": "${workspaceFolder}/app/Main.hs",
            "startupFunc": "",
            "startupArgs": "",
            "stopOnEntry": false,
            "mainArgs": "",
            "ghciPrompt": "H>>= ",
            "ghciInitialPrompt": "> ",
            "ghciCmd": "cabal repl -w ghci-dap --repl-no-load --builddir=${workspaceFolder}/.vscode/dist-cabal-repl",
            "ghciEnv": {},
            "logFile": "${workspaceFolder}/.vscode/phoityne.log",
            "logLevel": "WARNING",
            "forceInspect": false
        }
    ]
}

It seems from this file that

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

main :: IO ()
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

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

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:

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:

确定