DEV Community

Mohammed Q. Hussain
Mohammed Q. Hussain

Posted on

13

Setting Up PHP on Neovim with NvChad

  • Note: Tested and Worked with NvChad v2.0

Installing PHP's Language Server: phpactor

  • While in Neovim's command mode, execute the command :Mason to run Mason package manager.
  • Inside Mason, search for phpactor, an easy way to do that is through the search command "/phpactor".
  • Once you find it and the cursor is on its name, press "i" to install it. PHPActor requires Composer, make sure it's available on your system.

Configuring phpactor Properly on NvChad

  • After installing phpactor you need to edit NvChad's configuration file. The required configuration file will be found on the path ~/.config/nvim/lua/plugins/configs/lspconfig.lua.
    • Please note that the path of Neovim's configuration directory (which is ~/.config/nvim by default) may be different in your system, for example, if you installed Neovim through Flatpak, its path will be ~/.var/app/io.neovim.nvim/config/nvim.
  • In "lspconfig.lua" and just before the last line which is "return M" add the following lines to configure phpactor and make it run.
require("lspconfig").phpactor.setup {
  root_dir = function(_)
    return vim.loop.cwd()
  end,
  init_options = { 
    ["language_server.diagnostics_on_update"] = false,
    ["language_server.diagnostics_on_open"] = false,
    ["language_server.diagnostics_on_save"] = false,
    ["language_server_phpstan.enabled"] = false,
    ["language_server_psalm.enabled"] = false,
  }
}
Enter fullscreen mode Exit fullscreen mode

For some reason, I don't know why and I'm not sure if I'll dedicate time to find why, phpactor reported errors inaccurately for me, something like "The function 'foo' is not found" while 'foo' is there in the same PHP file. Due to that I've disabled PHPActor's diagnostics through setting "false" for the options "language_server.diagnostics_on_update", "language_server.diagnostics_on_open" and "language_server.diagnostics_on_save" in the code above. Feel free to enable them if you need and that's done by removing their lines or change "false" to "true" for them.

  • Finally, exit Neovim and run it again, try to edit a PHP file and phpactor should run now.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
maciejbaba profile image
Maciej Bąba

omg thanks it worked

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more