- 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
.
- Please note that the path of Neovim's configuration directory (which is
- 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,
}
}
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.
Top comments (1)
omg thanks it worked