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

2 client(s) attached to this buffer #395

Closed realtica closed 1 year ago

realtica commented 1 year ago

LSP client configuration

local config = {
  -- The command that starts the language server
  -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
  cmd = {

    -- 💀
    'java', -- 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',
    '-Xms1g',
    '--add-modules=ALL-SYSTEM',
    '--add-opens', 'java.base/java.util=ALL-UNNAMED',
    '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
    '-javaagent:'..jdtls_home..'/lombok.jar',
    -- 💀
    '-jar', jdtls_home .. '/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_home .. '/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', home .. '/.cache/jdtls/workspace'
  },

  -- 💀
  -- 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 = {
      -- format = {
      --   settings = {
      --     -- Use Google Java style guidelines for formatting
      --     -- To use, make sure to download the file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
      --     -- and place it in the ~/.local/share/eclipse directory
      --     url = "/.local/share/eclipse/eclipse-java-google-style.xml",
      --     profile = "GoogleStyle",
      --   },
      -- },
      signatureHelp = { enabled = true },
      contentProvider = { preferred = 'fernflower' }, -- Use fernflower to decompile library code
      -- Specify any completion options
      -- completion = {
      --   favoriteStaticMembers = {
      --     "org.hamcrest.MatcherAssert.assertThat",
      --     "org.hamcrest.Matchers.*",
      --     "org.hamcrest.CoreMatchers.*",
      --     "org.junit.jupiter.api.Assertions.*",
      --     "java.util.Objects.requireNonNull",
      --     "java.util.Objects.requireNonNullElse",
      --     "org.mockito.Mockito.*"
      --   },
      --   filteredTypes = {
      --     "com.sun.*",
      --     "io.micrometer.shaded.*",
      --     "java.awt.*",
      --     "jdk.*", "sun.*",
      --   },
      -- },
      -- Specify any options for organizing imports
      sources = {
        organizeImports = {
          starThreshold = 9999;
          staticStarThreshold = 9999;
        },
      },
      -- How code generation should act
      codeGeneration = {
        toString = {
          template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
        },
        hashCodeEquals = {
          useJava7Objects = true,
        },
        useBlocks = true,
      },
      -- If you are developing in projects with different Java versions, you need
      -- to tell eclipse.jdt.ls to use the location of the JDK for your Java version
      -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
      -- And search for `interface RuntimeOption`
      -- The `name` is NOT arbitrary, but must match one of the elements from `enum ExecutionEnvironment` in the link above
      -- configuration = {
      --   runtimes = {
      --     {
      --       name = "JavaSE-17",
      --       path = home .. "/.asdf/installs/java/corretto-17.0.4.9.1",
      --     },
      --     {
      --       name = "JavaSE-11",
      --       path = home .. "/.asdf/installs/java/corretto-11.0.16.9.1",
      --     },
      --     {
      --       name = "JavaSE-1.8",
      --       path = home .. "/.asdf/installs/java/corretto-8.352.08.1"
      --     },
      --   }
      -- }
    }
  },
  -- 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 = {}
  },
}

Eclipse.jdt.ls version

1.18.0

Steps to Reproduce

Opening a .java file in nvim

Expected Result

Client: jdtls (id: 1, bufnr: [1])
    filetypes:       
    autostart:       false
    root directory:  /home/realtica/projects/spring_minimal
    cmd:             java -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 -Xms1g --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -javaagent:/home/realtica/.local/share/nvim/mason/packages/jdtls/lombok.jar -jar /home/realtica/.local/share/nvim/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar -configuration /home/realtica/.local/share/nvim/mason/packages/jdtls/config_linux -data /home/realtica/.cache/jdtls/workspace

Actual Result

2 client(s) attached to this buffer: 

 Client: jdtls (id: 1, bufnr: [1])
    filetypes:       
    autostart:       false
    root directory:  /home/realtica/projects/spring_minimal
    cmd:             java -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 -Xms1g --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -javaagent:/home/realtica/.local/share/nvim/mason/packages/jdtls/lombok.jar -jar /home/realtica/.local/share/nvim/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar -configuration /home/realtica/.local/share/nvim/mason/packages/jdtls/config_linux -data /home/realtica/.cache/jdtls/workspace

 Client: jdtls (id: 2, bufnr: [1])
    filetypes:       java
    autostart:       true
    root directory:  /home/realtica/projects/spring_minimal
    cmd:             jdtls -configuration /home/realtica/.cache/jdtls/config -data /home/realtica/.cache/jdtls/workspace
mfussenegger commented 1 year ago

Looks like you're also using lspconfig.jdtls.setup which creates the second client

realtica commented 1 year ago

Looks like you're also using lspconfig.jdtls.setup which creates the second client

No, lspconfig.jdtls.setup is comment out.

Please, I closed this issue by mistake. :S

mfussenegger commented 1 year ago

Well, It must come from something in your configuration or some other plugin

arthureggert commented 1 year ago

@realtica not sure if you solved this already or not. But I had the same issue this morning and I was able to solve it. The thing is, I'm using LazyVim, and it was automatically calling the lspconfig.jdtls.setup for all the mason installed LSPs.

What I did to disable it was on my file plugins\lspconfig.lua

return {
  "neovim/nvim-lspconfig",
  opts = {
    setup = {
      jdtls = function(_, _)
        -- this will disable LazyVim from setting up jdtls automatically
        return true
      end,
    },
  },
}

With this config the only JDLTS attached is the one that I create with require("jdtls").start_or_attach(config)