【问题标题】:How do I skip external code when debugging in VS Code在 VS Code 中调试时如何跳过外部代码
【发布时间】:2018-05-13 09:08:52
【问题描述】:

vscode 中调试时,我想做一些“黑盒”,不要输入我没有编写的代码。我该怎么做?

【问题讨论】:

    标签: debugging visual-studio-code


    【解决方案1】:

    在您的启动或附加调试任务中,您可以输入一个

    “跳过文件”

    选项是

    “调试时要跳过的文件或文件夹名称或路径 glob 的数组。”

    例如,来自skipping node internals during debugging

    "skipFiles": [
      "${workspaceFolder}/node_modules/**/*.js",
      "${workspaceFolder}/yourLibToSkip/**/*.js"
    ]
    

    此外,您可以使用内置核心节点模块的“魔法参考”:

    "skipFiles": [
      "<node_internals>/**/*.js"
    ]
    

    【讨论】:

    • 您能否提供一些示例,我仍然无法阻止在调试时进入“node_modules”文件夹内的不同依赖项文件夹(即 ./node_modules/react-dom/lib/...)。启动任务的一部分是"skipFiles":"[./node_modules/**]"
    • @d2048 查看我对答案和包含的链接的编辑。
    • 这不适用于颤振。你能给我们展示一下颤振的完整例子吗?这看起来像 javascript
    • 那个“魔法参考”不起作用。我今天下载了 VSCode,调试了一个 TypeScript 项目,结果还是async_hooks.js
    • 虽然"skipFiles":["&lt;node_internals&gt;/**"] 适用于未附加的调试会话,但在附加进程的情况下似乎不起作用。
    【解决方案2】:

    我对设置设置的位置感到困惑,所以以防万一,如果您想同时跳过 node_modules deps 和 node_internals 文件,您的 .vscode/launch.json 文件应该如下所示:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Debug Tests",
                "type": "node",
                "request": "launch",
                ...
                "skipFiles": ["<node_internals>/**", "${workspaceFolder}/node_modules/**/*.js"]
            }
        ]
    }
    

    【讨论】:

    • 这是对我在 Windows 上使用 Chrome 调试 ReactJS 应用程序有用的答案。
    【解决方案3】:

    只有这对我有用。

    "debug.javascript.terminalOptions": {
        "skipFiles": [
            "<node_internals>/**"
        ]
    }
    

    【讨论】:

      【解决方案4】:

      这是我的 launch.json 文件(对我有用):

      {
          "version": "0.2.0",
          "configurations": [
              {
                  "type": "edge",
                  "request": "launch",
                  "name": "Launch Edge against localhost",
                  "url": "http://localhost:4200",
                  "webRoot": "${workspaceFolder}",
                  "skipFiles": [
                    "${workspaceFolder}/node_modules/**/*.js"
                  ]
              }
          ]
      }
      

      【讨论】:

        【解决方案5】:

        对于 Flutter 应用,将以下内容添加到您的用户设置中:

        "dart.debugExternalLibraries": false,
        "dart.debugSdkLibraries": false,
        

        【讨论】:

          【解决方案6】:

          为了扩大 Mauro Aguilar 的正确答案,这里是我的 launch.json 文件的完整内容。请注意,我正在使用 Chrome v.94 在 Windows 10 上使用 VS Code 1.60.2 调试 ReactJS 应用程序(大约 2021 年)。如果您使用的是 Linux 机器或 Mac,请使用 YMMV。

          {
              // 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": "pwa-chrome",
                      "request": "launch",
                      "name": "Launch Chrome against localhost",
                      "url": "http://localhost:3000",
                      "webRoot": "${workspaceFolder}",
                      "skipFiles": ["<node_internals>/**/*.js", "${workspaceFolder}/node_modules/**/*.js"]
                  },
              ]
          }
          

          【讨论】:

            猜你喜欢
            • 2020-10-10
            • 2021-05-09
            • 1970-01-01
            • 2017-10-06
            • 1970-01-01
            • 1970-01-01
            • 2022-11-04
            • 1970-01-01
            相关资源
            最近更新 更多