Skip to content

cristianradulescu/php-diagls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Diagnostics LSP Server

A Language Server Protocol (LSP) implementation for PHP that provides dynamic diagnostics using configurable external tools like PHP CS Fixer running in Docker containers.

Features

  • 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.json configuration files for project-specific settings

Installation

  1. Clone this repository
  2. Build the LSP server:
    make build

Configuration

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"
    }
  }
}

Configuration Options

  • enabled: Quick status toggle for the diagnostic provider
  • container: Name of the Docker container where the diagnostic provider tool is installed
  • path: Full path to the diagnostic provider executable inside the container
  • configFile: (Optional) Path to the diagnostic provider configuration file inside the container
  • format.enabled: (Optional) Enable document formatting using this provider
  • format.timeoutSeconds: (Optional) Nb of seconds to allow the formatting process to run

Document Formatting

The LSP server supports automatic document formatting using php-cs-fixer. When enabled, you can format PHP files using your editor's format command.

How It Works

  1. Stdin Processing: Content is sent to php-cs-fixer via stdin (no temporary files)
  2. Diff Analysis: php-cs-fixer returns a unified diff of proposed changes
  3. Safe Application: Changes are applied without modifying files on disk
  4. Container Integration: Formatting runs inside your specified Docker container

Enabling Formatting

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
      }
    }
  }
}

Usage

Editor Integration

Neovim

-- 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'})

Formatting Commands

Once configured, you can format documents using:

  • Neovim: :lua vim.lsp.buf.format()

About

PHP diagnostics LSP server

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages