PHP Development With Simpler LSP Setup in Neovim 0.11

I have two new client projects that I want to set up with Kirby CMS. That means I need to dust off my PHP skills, and whenever I dive back into a programming language I haven’t used in a while my first stop is my Neovim configuration. If my IDE is happy, I am happy.

Lucky me: Neovim 0.11 was released in March! Core maintainer Gregory Anders has written an excellent summary of what’s new and I want to draw your attention to the simpler LSP setup and configuration. I have been neglecting Neovim’s LSP capabilities until I started tinkering with game development for the Playdate, mainly because I felt overwhelmed and confused by the dichotomy between Neovim’s built-in LSP client since v0.5 and the plethora of plugins still needed to get things running. Neovim seems to be on a path to make all of that easier, which is great news!

What I did to attach a PHP language server to my PHP buffers:

  1. Choose a PHP language server from Microsoft’s list. After some Github digging, I decided to go with phpactor.
  2. Install phpactor with Mason.
  3. Create a config file at ~/.config/nvim/after/lsp/phpactor.lua.
  4. Enable LSP server with vim.lsp.enable({"phpactor"}). The name of the server has to correspond to the filename in the /lsp folder. Neovim will then scan the runtime path and auto-enable the selected servers.
  5. Explicitly opt-in for virtual diagnostic text with vim.diagnostic.config({ virtual_text = true }).

That’s it—8 lines of configuration give me basic LSP capabilities for PHP. The rest are deleted key mappings as Neovim also introduced some sensible global default keymaps that I will use from now on.