LunarVim / Launch.nvim

🚀 Launch.nvim is modular starter for Neovim.
GNU General Public License v3.0
2k stars 475 forks source link

problems with lombok #115

Closed AntDavidLima closed 1 year ago

AntDavidLima commented 1 year ago

Hi, I am having problems getting Lombok to work on nvim-basic-ide.

I installed jdtls using Mason and added it to the server's table. When I open a project that has lombok on it, it recognizes the lombok anotations and even gives me autocompletion and spelling errors, but when I try to use autogenerated methods, such as @Getter, @Setter, and @AllArgsConstructor, on another class, it says that those methods do not exist, and on the class that has these anotations, it gives me warnings saying that the properties are not been used.

I got it to work when I uninstalled jdtls from the Mason UI, installed it on my system using jdtls-launcher and added the following settings to jdtls:

return {  
  cmd = { "jdtls" },
  root_dir = function(fname)
    return require'lspconfig'.util.root_pattern('pom.xml', 'gradle.build', '.git')(fname) or vim.fn.getcwd()  
  end
}

But every time I open NeoVIM, Mason automatically starts installing jdtls again, and when it finishes installing, Lombok stops working.

It happens even when I remove jdtls from the ensure_installed table in mason-lspconfig settings.

I tried to use nvim-jdtls for this server instead of lspconfig, and it stopped automatically installing jdtls via Mason when I started NeoVIM, but Lombok stopped working too.

Does anyone know how to stop this behavior from lspconfig? or have another possible solution?

Thanks for the help.

EnriqueBravo115 commented 1 year ago

you solve it?

AntDavidLima commented 1 year ago

Yes, I was able to get it working using nvim-jdtls.

After installing nvim-jdtls using Packer, I installed jdtls manually on my machine, using jdtls-launcher and created a folder called ftplugin, at the root of my nvim, and inside it a file called java.lua with the following content:

-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = "/home/david/jdtls/workspace/" .. project_name

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",
    "-javaagent:/usr/share/java/lombok.jar",
    "--add-modules=ALL-SYSTEM",
    "--add-opens",
    "java.base/java.util=ALL-UNNAMED",
    "--add-opens",
    "java.base/java.lang=ALL-UNNAMED",

    -- 💀
    "-jar",
    "/home/david/.local/opt/jdtls-launcher/jdtls/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",
    "/home/david/.local/opt/jdtls-launcher/jdtls/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", "pom.xml" },
  -- 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 = {
      eclipse = {
        downloadSources = true,
      },
      configuration = {
        updateBuildConfiguration = "interactive",
      },
      maven = {
        downloadSources = true,
        updateSnapshots = true,
      },
    },
  },
  -- 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.setup").add_commands()
require("jdtls").start_or_attach(config)

Note that you will need to modify some paths to the equivalents on your machine. Most paths that need to be modified have a comment with a :skull: above them.

Also note that I am passing the lombok that was manually downloaded from the lombok website as a java agent, this will make the integration with Lombok work.

To continue having some features that I had using jdtls installed by mason, I kept jdtls in mason's server list and disabled some of its features in the handlers.lua file, the code for that is as follows:

M.on_attach = function(client, bufnr)
  if client.name == "jdtls" then
    client.handlers["textDocument/publishDiagnostics"] = function() end

    client.server_capabilities.codeActionProvider = nil
    client.server_capabilities.completionProvider = nil
  end

  if client.name == "sqls" then
    client.server_capabilities.documentFormattingProvider = false
  end

  if client.name == "tsserver" then
    client.handlers["textDocument/publishDiagnostics"] = function() end
  end

  lsp_keymaps(bufnr)
  local status_ok, illuminate = pcall(require, "illuminate")
  if not status_ok then
    return
  end
  illuminate.on_attach(client)
end

If you want to see the full code of my settings, this repository is a fork of nvim-basic-ide with my settings.

I hope it helps. I'll keep the issue open to see if anyone can resolve the issue without using nvim-jdtls.

EnriqueBravo115 commented 1 year ago

Finally i solve it, i think i have a bug in my pc, but using metals of scala solve the error with lombok and improve a lot the performance with java, also i can go to the implementation of libraries like intellij and see all methods, interfaces etc 💅🏻

Rishabh672003 commented 1 year ago

i have pinned the issue, so closing this as everyone will be able to see it as it is