VS Code 中多个文件中的断点?

lte*_*e__ 7 visual-studio-code vscode-settings vscode-debugger

我有一个包含多个文件/模块的 Python 项目,我正在尝试调试。我安装了Python 扩展,并在其中放置了一堆断点 - 一些在当前文件中,一些在另一个文件/模块中。当前文件中的断点工作正常,但是,其他文件中的断点则不然。我在设置调试器时缺少一个步骤吗?在 Google 上找不到针对此特定问题的任何内容,教程仅在一个文件中显示调试,并且工作正常。如果我尝试右键单击并转到另一个模块中任何函数的定义,这也可以正常工作,因此项目知道多个模块(我在 VS Code 中打开了整个目录),断点则不然。

Mat*_*att 11

Ran into the same issue. In case you still need to know, this is how I resolved it.

  1. Create a workspace in vscode
  2. Add the folders you want into the workspace with all the files you need. We need to do this to create the launch.json file
  3. Click on the Debug Icon or Ctrl+Shift+D
  4. Click the gear icon in the debug sidebar at the top. It will say open launch.json
  5. If one is not created, it will automatically create it for and it should look like:
{
    // 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": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

Run Code Online (Sandbox Code Playgroud)
  1. Add in justMyCode, but set to false
{
    // 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": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}

Run Code Online (Sandbox Code Playgroud)
  1. Save and start debugging. You should be able to step into other modules now.

A screenshot of what the debug screen configuration should now look like: Python调试配置

You can create different configs if you don't want to debug other modules or do things as well.