A Language Server Protocol (LSP) implementation for PHP that provides dynamic diagnostics using configurable external tools like PHP CS Fixer running in Docker containers.
- Docker Integration: Run PHP CS Fixer and other tools inside Docker containers
- Diagnostics: Real-time code analysis and issue detection
- Document Formatting: Automatic code formatting using php-cs-fixer
- Configurable: Use
.php-diagls.jsonconfiguration files for project-specific settings
- Clone this repository
- Build the LSP server:
make build
Create a .php-diagls.json file in your project root directory to configure the diagnostics tools:
{
"diagnosticsProviders": {
"phpcsfixer": {
"enabled": true,
"container": "my-php-container",
"path": "/usr/local/bin/php-cs-fixer",
"configFile": ".php-cs-fixer.dist.php",
"format": {
"enabled": true
}
},
"phpstan": {
"enabled": false,
"container": "my-php-container",
"path": "/usr/local/bin/phpstan",
"configFile": "phpstan.neon"
},
"phplint": {
"enabled": true,
"container": "my-php-container",
"path": "/usr/local/bin/php"
}
}
}enabled: Quick status toggle for the diagnostic providercontainer: Name of the Docker container where the diagnostic provider tool is installedpath: Full path to the diagnostic provider executable inside the containerconfigFile: (Optional) Path to the diagnostic provider configuration file inside the containerformat.enabled: (Optional) Enable document formatting using this providerformat.timeoutSeconds: (Optional) Nb of seconds to allow the formatting process to run
The LSP server supports automatic document formatting using php-cs-fixer. When enabled, you can format PHP files using your editor's format command.
- Stdin Processing: Content is sent to php-cs-fixer via stdin (no temporary files)
- Diff Analysis: php-cs-fixer returns a unified diff of proposed changes
- Safe Application: Changes are applied without modifying files on disk
- Container Integration: Formatting runs inside your specified Docker container
Add the format configuration to your php-cs-fixer provider:
{
"diagnosticsProviders": {
"phpcsfixer": {
"enabled": true,
"container": "my-php-container",
"path": "/usr/local/bin/php-cs-fixer",
"configFile": ".php-cs-fixer.dist.php",
"format": {
"enabled": true
}
}
}
}-- lua/lsp/php_diagls.lua
return {
cmd = { '/path/to/php-diagls' },
root_markers = { '.git', 'composer.json' },
filetypes = { 'php'},
}Then in the LSP configuration:
vim.lsp.enable({'php-diagls'})Once configured, you can format documents using:
- Neovim:
:lua vim.lsp.buf.format()