bscan / PerlNavigator

Perl Language Server that includes syntax checking, perl critic, and code navigation
MIT License
198 stars 39 forks source link

Error with Nvchad #127

Closed manuvillalba-uclm closed 5 months ago

manuvillalba-uclm commented 6 months ago

Hello, using the Neovim 0.9.5 with nvchad

I got the following error when opening Perl files

[lspconfig] unhandled error: ...squashfs-root/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:663: cmd: expected string, got nil

I'm using nvchad 2.5 with nvim-lspconfig and mason.nvim

  {
    "neovim/nvim-lspconfig",
    config = function()
      require("nvchad.configs.lspconfig").defaults()
      require "configs.lspconfig"
    end,
  },
  {
    "williamboman/mason.nvim",
    opts = {
        ensure_installed = {
            "lua-language-server", "stylua", "html-lsp", "css-lsp" , "prettier"
        },
    },
  },

I have tried multiple configurations, I have tried https://github.com/bscan/PerlNavigator/issues/88, but nothing seems to work.

require'lspconfig'.perlnavigator.setup{
    settings = {
        perlnavigator = {
            perlPath = '/usr/bin/perl',
            perltidyProfile = '/usr/bin/perltidy',
            perlcriticProfile = "/usr/bin/perlcritic"
        }
    }
}

I think Mason is ignoring my configuration. Other LSP like pyright just work

mrsdizzie commented 5 months ago

For Perl Navigator you need to specify the cmd because it is empty by default (for whatever reason): https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/perlnavigator.lua

By default, perlnavigator doesn't have a cmd set. This is because nvim-lspconfig does not make assumptions about your path. You have to install the language server manually.

So adjusting your example above, should be something like

require'lspconfig'.perlnavigator.setup{
cmd = { "$HOME/.local/share/nvim/mason/packages/perlnavigator/perlnavigator" },
settings = {
        perlnavigator = {
            perlPath = '/usr/bin/perl',
            perltidyProfile = '/usr/bin/perltidy',
            perlcriticProfile = "/usr/bin/perlcritic"
        }
    },
})

$HOME being the actual path of your home or wherever your copy of neovim is set to save these things

bscan commented 5 months ago

Thanks @mrsdizzie, this makes sense. When this config was added, the recommended method of installing the perlnavigator was cloning the repo and building the js files. Now, it's hosted on npm and includes a bin file, so a user can install it globally via sudo npm install -g perlnavigator-server and then use perlnavigator as the command.

Similarly, for people using mason-lspconfig, it will point people to just use perlnavigator as the command. https://github.com/williamboman/mason-lspconfig.nvim/blob/44509689b9bf3984d729cc264aacb31cb7f41668/lua/mason-lspconfig/server_configurations/perlnavigator/init.lua#L3

Looks like that's the recommended method for many other nvim-lspconfig servers as well, such as the bash-language-server. It installs from npm and then uses a global command. Bash: https://github.com/neovim/nvim-lspconfig/blob/e25c4cdecd3d58c0deccce0f372426c8c480bcce/lua/lspconfig/server_configurations/bashls.lua#L28 Other examples: https://github.com/search?q=repo%3Aneovim%2Fnvim-lspconfig%20npm&type=code

manuvillalba-uclm commented 5 months ago

This worked:

So adjusting your example above, should be something like

require'lspconfig'.perlnavigator.setup{
cmd = { "$HOME/.local/share/nvim/mason/packages/perlnavigator/perlnavigator" },
settings = {
        perlnavigator = {
            perlPath = '/usr/bin/perl',
            perltidyProfile = '/usr/bin/perltidy',
            perlcriticProfile = "/usr/bin/perlcritic"
        }
    },
})

For context, I have only been using lsp for a week. I installed it with :Mason

I think it should be mentioned in the README, in the nvim part, that you have to add cmd.

Thank you @mrsdizzie and @bscan

bscan commented 5 months ago

Thanks @manuvillalba-uclm! I just updated the README with https://github.com/bscan/PerlNavigator/commit/5b88333ea26119255964dde79d207df1ef548e49

I also submitted a pull request back to nvim-lspconfig to include the npm installation method and a default command: https://github.com/neovim/nvim-lspconfig/pull/3106

I'd love input if anyone is available to double-check my pull request. I don't have nvim-installer setup, so I wasn't able to test the code.