php-lsp 0.1.0

A PHP Language Server Protocol implementation
php-lsp-0.1.0 is not a library.

php-lsp

A PHP Language Server Protocol (LSP) implementation written in Rust.

Features

  • Diagnostics — syntax errors reported in real time as you type
  • Completion — keywords, functions, classes, interfaces, traits, methods, properties, constants, and cross-file symbols from all open documents
  • Hover — signatures for functions, classes (with extends/implements), interfaces, and traits
  • Go-to-definition — jump to where a symbol is declared, including across open files
  • Document symbols — outline of all functions, classes, methods, properties, and constants in the file

Installation

cargo install php-lsp

Or build from source:

git clone https://github.com/jorgsowa/php-lsp
cd php-lsp
cargo build --release
# binary at target/release/php-lsp

Editor Setup

PHPStorm (2023.2+)

  1. Open Settings → Languages & Frameworks → Language Servers
  2. Click + and configure:
    • Name: php-lsp
    • Language: PHP
    • Command: /path/to/php-lsp
  3. Set file pattern to *.php

Neovim (via nvim-lspconfig)

vim.api.nvim_create_autocmd("FileType", {
  pattern = "php",
  callback = function()
    vim.lsp.start({
      name = "php-lsp",
      cmd = { "/path/to/php-lsp" },
      root_dir = vim.fs.root(0, { "composer.json", ".git" }),
    })
  end,
})

VS Code

Use the custom LSP client extension or any extension that supports arbitrary LSP servers. Set the server command to the php-lsp binary.

How It Works

The server communicates over stdin/stdout using the Language Server Protocol. It uses php-parser-rs to parse PHP source into an AST, which is cached per document and reused across all requests.

License

MIT