VSCode launch.json add PHPStan and syntax check debug functions

After XDebug extensions added, fix your launch.json for more debug functions as console output of text editor like EditPlus or Notepad++ does.

In Linux VSCode:
{
    "version": "0.2.0",    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        },
        {
            "name": "PHPStan",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "runtimeArgs": [ "/u/php7/phpstan.phar","--no-progress", "--level=4", "--configuration=/u/php7/phpstan.neon", "analyse" ],
            "cwd": "${fileDirname}"
        },
        {
            "name": "Syntax Check",
            "request": "launch",
            "type": "php",
            "program": "${file}",
            "runtimeArgs": [ "-l" ],
            "cwd": "${workspaceFolder}"
        }
    ]
}

In Windows VSCode:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9900 // Be aware not conflict with fastcgi port
}, {
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9900
}, {
"name": "PHPStan",
"type": "php",
"request": "launch",
"program": "${file}",
"runtimeArgs": ["-c", "c:/www/nginx/php72/php.ini", "c:/www/tool/CodeSniffer/phpstan.phar","--no-progress", "--level=4", "--configuration=c:/www/tool/CodeSniffer/phpstan.neon", "analyse"],
"cwd": "${workspaceRoot}"
}, {
"name": "PHPPhan",
"type": "php",
"request": "launch",
"program": "${file}",
"runtimeArgs": ["-c","c:/www/nginx/php72/php.ini","c:/www/tool/CodeSniffer/phan.phar"],
"cwd": "${workspaceRoot}"
}, {
"name": "PHPSA",
"type": "php",
"request": "launch",
"program": "${file}",
"runtimeArgs": ["-c","c:/www/nginx/php72/php.ini","c:/www/nginx/www/php/phpsa/phpsa.phar","check"],
"cwd": "${workspaceRoot}"
}, {
"name": "Syntax Check",
"request": "launch",
"type": "php",
"program": "${file}",
"runtimeArgs": ["-l"], // Syntax only
"cwd": "${workspaceRoot}"
}
]
}

From above example of PHPStan, you could add more command like debug utilities like PHAN, PHPCS... . Convert command line into JSON array arguments by split with 'SPACE CHAR'.

i.e:
The original linux command line is:

/u/php7/bin/php /u/php7/phpstan.phar --no-progress --level=4 --configuration=/u/php7/phpstan.neon analyse $1




Predefined variables

The following predefined variables are supported:

    ${workspaceFolder} - the path of the folder opened in VS Code
    ${workspaceFolderBasename} - the name of the folder opened in VS Code without - any slashes (/)
    ${file} - the current opened file
    ${relativeFile} - the current opened file relative to workspaceFolder
    ${fileBasename} - the current opened file's basename
    ${fileBasenameNoExtension} - the current opened file's basename with no file extension
    ${fileDirname} - the current opened file's dirname
    ${fileExtname} - the current opened file's extension
    ${cwd} - the task runner's current working directory on startup
    ${lineNumber} - the current selected line number in the active file
    ${selectedText} - the current selected text in the active file

Note: The ${workspaceRoot} variable is deprecated in favor of the ${workspaceFolder} variable.
Environment variables

You can also reference environment variables through ${env:Name} syntax (for example, ${env:PATH})

Be aware the ${workspaceRoot} variable has been deprecated in favor of the ${workspaceFolder} variable. It was deprecated (and no longer documented) in order to align better with Multi-root workspace support.

留言

這個網誌中的熱門文章

星之卡比 白屏 當機問題終於解決!! Wii

使用 Mikrotik RouterOS 執行家長管理 (定時網站存取權)

修改 自然輸入法V11注音免費版 / 輸入框與選字框字型大小