mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1.09k stars 62 forks source link

client_id: expected number, got nil #507

Closed shwahnim closed 1 year ago

shwahnim commented 1 year ago

LSP client configuration

local jdtls_installation = "/home/mohammad/.local/share/nvim/mason/bin/jdtls"

local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = "/home/mohammad/.local/share/nvim/mason/packages/jdtls/data_dir/" .. project_name

-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
local config = {
  -- The command that starts the language server
  -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
  cmd = {

    -- 💀
    "/home/mohammad/.sdkman/candidates/java/21.ea.25-open", -- or '/path/to/java17_or_newer/bin/java'
    -- depends on if `java` is in your $PATH env variable and if it points to the right version.

    "-Declipse.application=org.eclipse.jdt.ls.core.id1",
    "-Dosgi.bundles.defaultStartLevel=4",
    "-Declipse.product=org.eclipse.jdt.ls.core.product",
    "-Dlog.protocol=true",
    "-Dlog.level=ALL",
    "-Xmx1g",
    "--add-modules=ALL-SYSTEM",
    "--add-opens",
    "java.base/java.util=ALL-UNNAMED",
    "--add-opens",
    "java.base/java.lang=ALL-UNNAMED",

    -- 💀
    "-jar",
    jdtls_installation .. "/plugins/org.eclipse.equinox.launcher_" .. "1.6.400.v20210924-0641" .. ".jar",
    -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       ^^^^^^^^^^^^^^
    -- Must point to the                                                     Change this to
    -- eclipse.jdt.ls installation                                           the actual version

    -- 💀
    "-configuration",
    jdtls_installation .. "/config_linux",
    -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        ^^^^^^
    -- Must point to the                      Change to one of `linux`, `win` or `mac`
    -- eclipse.jdt.ls installation            Depending on your system.

    -- 💀
    -- See `data directory configuration` section in the README
    "-data",
    workspace_dir,
  },

  -- 💀
  -- This is the default if not provided, you can remove it. Or adjust as needed.
  -- One dedicated LSP server & client will be started per unique root_dir
  root_dir = require("jdtls.setup").find_root { ".git", "mvnw", "gradlew" },

  -- Here you can configure eclipse.jdt.ls specific settings
  -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
  -- for a list of options
  settings = {
    java = {},
  },

  -- Language server `initializationOptions`
  -- You need to extend the `bundles` with paths to jar files
  -- if you want to use additional eclipse.jdt.ls plugins.
  --
  -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
  --
  -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
  init_options = {
    bundles = {},
  },
}
-- This starts a new client & server,
-- or attaches to an existing client & server depending on the `root_dir`.
require("jdtls").start_or_attach(config)

Eclipse.jdt.ls version

1.6.400.v20210924-0641

Steps to Reproduce

i'm using maven wrapper, neovim version is v0.9.1

Expected Result

Should not error out

Actual Result

Spawning language server with cmd: `/home/mohammad/.sdkman/candidates/java/21.ea.25-open` failed with error message: EACCES: permission denied
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/local/share/nvim/runtime/filetype.lua:21: Error executing lua: /usr/local/share/nvim/runtime/filetype.lua:22: BufReadPost Autocommands for "*"..FileT
ype Autocommands for "*"..function <SNR>1_LoadFTPlugin[19]..script /home/mohammad/dev/nvim/after/ftplugin/java.lua: Vim(runtime):E5113: Error while calling lua chunk: /usr/local/share/
nvim/runtime/lua/vim/lsp.lua:1630: client_id: expected number, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1630: in function 'buf_attach_client'
        ...ad/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/setup.lua:33: in function 'start'
        ...ad/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls/setup.lua:286: in function 'start_or_attach'
        ...mohammad/.local/share/nvim/lazy/nvim-jdtls/lua/jdtls.lua:35: in function 'start_or_attach'
        /home/mohammad/dev/nvim/after/ftplugin/java.lua:73: in main chunk
        [C]: in function 'nvim_cmd'
        /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
shwahnim commented 1 year ago

wrong jdtls_installation path