phpneovim

How to properly set root directory for phpactor in neovim


I am trying to figure out how to make phpactor work with neovim for one of my legacy projects.

I am using the latest neovim + kickstart, my setup is quite basic:

phpactor = {
  cmd = { "phpactor", "language-server" },
  filetypes = { "php" },


  root_dir = function()
    return "/srv/home/milos/projects/legacy-php"
  end,


  on_new_config = function(config, root_dir)
    config.cmd_cwd = root_dir
    config.cmd_env = vim.fn.environ()
  end,
}

however i always get the same thing when i try to edit some file: "Client phpactor quit with exit code 255 and signal 0. Check logs for errors..."

I check logs and I see:

[ERROR][2025-06-05 12:28:41] ...p/_transport.lua:36 "rpc"   "phpactor"  "stderr"    "  Phpactor Language Server must be initialized with a root URI, NULL provided  \n                                                                               \n\nlanguage-server [--address ADDRESS] [--no-loop]\n\n"

Not sure what is needed, help would be highly appriciated.


Solution

  • Try following changes:

    phpactor = {
      cmd = { "phpactor", "language-server" },
      filetypes = { "php" },
    
      root_dir = function()
        return "/srv/home/milos/projects/legacy-php"
      end,
    
      on_new_config = function(config, root_dir)
        config.cmd_cwd = root_dir
        config.cmd_env = vim.fn.environ()
        config.root_uri = "file://" .. root_dir  -- Set the root URI
      end,
    }