Search code examples
linuxubuntuluaneovim

Spawning language server with cmd: `lua-language-server`


I've recently transferred from Packer plugin manager to Lazy.

Utilizing LSP, LspConfig, Mason, MasonLspConfig with several language servers for programming.

The problem is that Neovim is having troubles accessing these servers. It worked with the Packer package manager. Maybe I misconfigured something, but I'm clueless what the issue might be.

The language servers are installed and added to PATH.

Spawning language server with cmd: `lua-language-server` failed with error message: EACCES: permission denied

"lua-language-server" command as such is callable.

I'm using Fish shell as a default shell.

Here is my plugin configuration file:

return {
    { "lvimuser/lsp-inlayhints.nvim" },
    { 
        "neovim/nvim-lspconfig",
        dependencies = { "lvimuser/lsp-inlayhints.nvim" },
        config = function()
          local lspconfig = require("lspconfig")

          lspconfig.gopls.setup({
            on_attach = function(client, bufnr)
              require("settings/shared").on_attach(client, bufnr)
              require("lsp-inlayhints").setup({
                inlay_hints = {
                  type_hints = {
                    prefix = "=> "
                  },
                },
              })
              require("lsp-inlayhints").on_attach(client, bufnr)
              require("illuminate").on_attach(client)
            end,
            settings = {
              gopls = {
                analyses = {
                  nilness = true,
                  unusedparams = true,
                  unusedwrite = true,
                  useany = true,
                },
                experimentalPostfixCompletions = true,
                gofumpt = true,
                staticcheck = true,
                usePlaceholders = true,
                hints = {
                  assignVariableTypes = true,
                  compositeLiteralFields = true,
                  compositeLiteralTypes = true,
                  constantValues = true,
                  functionTypeParameters = true,
                  parameterNames = true,
                  rangeVariableTypes = true,
                }
              },
            },
      })
      end
    },

    { "williamboman/mason.nvim" },
    { "Afourcat/treesitter-terraform-doc.nvim" },
    { "williamboman/mason-lspconfig.nvim", 
        dependencies = { "williamboman/mason.nvim" },
        config = function()
            local mason_lspconfig = require("mason-lspconfig")

            mason_lspconfig.setup({
                PATH = "prepend",
                ensure_installed = {
                  "eslint",
                  "gopls", -- WARNING: This could be an issue with goenv switching.
                  "marksman",
                  "rust_analyzer",
                  "sumneko_lua",
                  "terraformls",
                  "tflint",
                  "tsserver",
                  "yamlls",
                }
            })

            mason_lspconfig.setup_handlers({
                function(server_name)
                    require("lspconfig")[server_name].setup({
                    on_attach = function(client, bufnr)
                        require("settings/shared").on_attach(client, bufnr)
                        require("illuminate").on_attach(client)

                        if server_name == "terraformls" then
                        require("treesitter-terraform-doc").setup()
                        end
                    end
                  })
                end
                })
            end
            },

  { "simrat39/symbols-outline.nvim",
    config = function()
      require("symbols-outline").setup({
        -- autofold_depth = 1, -- h: close, l: open, W: close all, E: open all
        auto_close = false,
        highlight_hovered_item = true,
        position = "left",
        width = 15,
        symbols = {
          File = { icon = "", hl = "GruvboxAqua" }, -- TSURI
          Module = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
          Namespace = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
          Package = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
          Class = { icon = "𝓒", hl = "GruvboxGreen" }, -- TSType
          Method = { icon = "ƒ", hl = "GruvboxOrange" }, -- TSMethod
          Property = { icon = "", hl = "GruvboxOrange" }, -- TSMethod
          Field = { icon = "", hl = "GruvboxRed" }, -- TSField
          Constructor = { icon = "", hl = "TSConstructor" },
          Enum = { icon = "ℰ", hl = "GruvboxGreen" }, -- TSType
          Interface = { icon = "ﰮ", hl = "GruvboxGreen" }, -- TSType
          Function = { icon = "", hl = "GruvboxYellow" }, -- TSFunction
          Variable = { icon = "", hl = "GruvboxPurple" }, -- TSConstant
          Constant = { icon = "", hl = "GruvboxPurple" }, -- TSConstant
          String = { icon = "𝓐", hl = "GruvboxGray" }, -- TSString
          Number = { icon = "#", hl = "TSNumber" },
          Boolean = { icon = "⊨", hl = "TSBoolean" },
          Array = { icon = "", hl = "GruvboxPurple" }, -- TSConstant
          Object = { icon = "⦿", hl = "GruvboxGreen" }, -- TSType
          Key = { icon = "🔐", hl = "GruvboxGreen" }, -- TSType
          Null = { icon = "NULL", hl = "GruvboxGreen" }, -- TSType
          EnumMember = { icon = "", hl = "GruvboxRed" }, -- TSField
          Struct = { icon = "𝓢", hl = "GruvboxGreen" }, -- TSType
          Event = { icon = "🗲", hl = "GruvboxGreen" }, -- TSType
          Operator = { icon = "+", hl = "TSOperator" },
          TypeParameter = { icon = "𝙏", hl = "GruvboxRed" } --TTSParameter
        },
      })
    end
  },

  { "mfussenegger/nvim-lint",
    config = function()
      local lint = require("lint")
      lint.linters_by_ft = {
        go = { "golangcilint" }, -- ~/.golangci.yml
      }
      -- see ./lsp.lua for calls to this plugin's try_lint() function.
    end
  },
}

This is what :LspInfo says:

Detected filetype:   lua

     { 0 client(s) attached to this buffer:
     {
     { Other clients that match the filetype: lua

       Config: sumneko_lua
        filetypes:         lua
        root directory:    /home/user/.config/nvim
        cmd:               lua-language-server
        cmd is executable: Unable to find executable. Please check your path    and ensure the server is
                                 installed
        autostart:         true
        custom handlers:

       Configured servers list: gopls, terraformls, yamlls, tflint, eslint, tsserver, marksman, rust_analyzer, sumneko_lua

Solution

  • After I rebooted the system, the lsp-config detected the lua-language-server. My guess is that the PATH wasn't properly sourced.

    For anyone having similar issues - make sure you have the language servers installed, added to the PATH correctly, and don't forget to source your config file with variables.

    Here are my variables for the lua-language-server and gopls server in the fish shell format:

    # Lua
    set -gx PATH ~/.config/lsp/lua-language-server/bin $PATH
    
    # Go
    set -gx GOPATH ~/go
    set -gx PATH /usr/local/go/bin $PATH
    set -gx PATH $GOPATH/bin $PATH
    

    And here they are in the bash format:

    # Lua
    export PATH=$PATH:$HOME/.config/lsp/lua-language-server/bin
    
    # Go
    export GOPATH=$HOME/go
    export PATH=$PATH:/usr/local/go/bin
    export PATH=$PATH:$GOPATH/bin