使用 PHP + XDEBUG 时在 VS Code 中显示长字符串

Sha*_*n C 9 php xdebug visual-studio-code

我正在使用 VS Code 进行 PHP Web 开发。带有 XDEBUG 的 VS Code 在显示字符串值变量方面似乎受到严重限制。变量和监视窗口仅限于窗口宽度或第一个换行符。

您可以通过评估字符串在调试控制台中显示更多内容,但最多只能超过 1000 个字符。该字符串被简单地截断。当您复制值并粘贴到编辑器窗口中时,也会发生同样的情况。

当处理任何类型的现实生活中的 HTML 时,这是相当不充分的。

我正在使用 VS Code 1.57.1​​ 和 XDEBUG 1.16.1(和 PHP Intelephense 1.7.1)

有人知道调整这个的方法吗?

Sha*_*n C 13

答案如下:

Visual Studio Code 调试数组评估

基本上你需要添加一个max_data: -1到启动配置文件。

例如

{
    // 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": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9004,
            "xdebugSettings": {
                "max_children": 128,
                "max_data": -1,
                "max_depth": 3
            },
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9004,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ],
}
Run Code Online (Sandbox Code Playgroud)