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

Gradle project not recognized #490

Closed takadev15 closed 1 year ago

takadev15 commented 1 year ago

LSP client configuration

Here's my nvim-jdtls configurations

local home = os.getenv("HOME")
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle", "settings.gradle" }
local root_dir = require('jdtls.setup').find_root(root_markers)
if root_dir == "" then
  return
end

local workspace_folder = "/home/takadev/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")

local extendedClientCapabilities = require("jdtls").extendedClientCapabilities
extendedClientCapabilities.resolveAdditionalTextEditsSupport = true

local config = {
  cmd = {
    '/usr/lib/jvm/java-17-openjdk/bin/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',
    '-javaagent:/home/takadev/Repo/eclipse.jdt.ls/lombok.jar',
    '-Xmx4g',
    '--add-modules=ALL-SYSTEM',
    '--add-opens', 
    'java.base/java.util=ALL-UNNAMED',
    '--add-opens', 
    'java.base/java.lang=ALL-UNNAMED',
    '-jar', 
    '/home/takadev/Repo/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar',
    '-configuration', 
    '/home/takadev/Repo/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux',
    '-data', 
    workspace_folder,
  },
  root_dir = root_dir,
  settings = {
    java = {
      signatureHelp = { enabled = true },
      contentProvider = { preferred = "fernflower" },
      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.*",
        },
        importOrder = {
          "java",
          "javax",
          "com",
          "org"
        },
        filteredTypes = {
          "com.sun.*",
          "io.micrometer.shaded.*",
          "java.awt.*",
          "jdk.*",
          "sun.*",
        },
      },
      sources = {
        organizeImports = {
          starThreshold = 9999,
          staticStarThreshold = 9999,
        },
      },
      codeGeneration = {
        toString = {
          template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
        },
        hashCodeEquals = {
          useJava7Objects = true,
        },
        useBlocks = true,
      },
      configuration = {
        runtimes = {
          {
            name = "JavaSE-1.8",
            path = "/usr/lib/jvm/java-8-openjdk/",
          },
          {
            name = "JavaSE-17",
            path = "/usr/lib/jvm/java-17-openjdk/",
          },
        },
      },
    },
  },
  init_options = {
    extendedClientCapabilities = extendedClientCapabilities,
  },
}

M.setup = function (on_attach, capabilities)
  config.on_attach = on_attach
  config.capabilities = capabilities
  vim.api.nvim_create_autocmd({ "FileType"}, {
    pattern = "java",
    callback = function()
      require("jdtls").start_or_attach(config)
    end,
    desc = "Start java language server"
  })
end

Eclipse.jdt.ls version

No response

Steps to Reproduce

The problems only appear on my work java's project. I already tested this plugin on other file with similar file structure with my workfile (https://github.com/FabricMC/fabric) and it works perfectly.

i'm suspecting the problem lies on dependecies on my works java project. Since one of the dependencies used is a my company specific private registry. even tough i already specified the keys in local.properties on root project i suspected this information isn't used by jdtls.

Expected Result

lsp.log for success lsp attaching (fabric project)

[ERROR][2023-05-18 15:54:23] .../vim/lsp/rpc.lua:734    "rpc"   "/usr/lib/jvm/java-17-openjdk/bin/java" "stderr"        "WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\n"
[WARN][2023-05-18 15:55:12] ...lsp/handlers.lua:137     "The language server jdtls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-05-18 15:55:12] ...lsp/handlers.lua:535    "May 18, 2023, 3:55:12 PM Command _java.reloadBundles.command not supported on client"
[ERROR][2023-05-18 15:55:13] ...lsp/handlers.lua:535    "May 18, 2023, 3:55:13 PM Error occured while building workspace. Details: \n message: Incompatible conditional operand types Codec<Map<RegistryKey<E>,E>> and UnboundedMapCodec<?,?>; code: 16777232; resource: /home/takadev/dir/data/learn/java/fabric/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/mixin/dimension/RegistryCodecsMixin.java; line: 58\n message: The return types are incompatible for the inherited methods ParentElement.getFocused(), EntryListWidget<ChannelList.Entry>.getFocused(); code: 67109283; resource: /home/takadev/dir/data/learn/java/fabric/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/channeltest/ChannelList.java; line: 27\n message: The return types are incompatible for the inherited methods ParentElement.children(), EntryListWidget<ChannelList.Entry>.children(); code: 67109283; resource: /home/takadev/dir/data/learn/java/fabric/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/channeltest/ChannelList.java; line: 27\n message: Bound mismatch: The type ChannelList.Entry is not a valid substitute for the bounded parameter <E extends EntryListWidget.Entry<E>> of the type EntryListWidget<E>; code: 16777742; resource: /home/takadev/dir/data/learn/java/fabric/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/channeltest/ChannelList.java; line: 27\n message: The type EntryListWidget.Entry is not visible; code: 16777219; resource: /home/takadev/dir/data/learn/java/fabric/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/channeltest/ChannelList.java; line: 46\n message: The method render(MatrixStack, int, int, int, int, int, int, int, boolean, float) of type ChannelList.Entry must override or implement a supertype method; code: 67109498; resource: /home/takadev/dir/data/learn/java/fabric/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/channeltest/ChannelList.java; line: 54"

Actual Result

lsp.log for when i started jdtls on work's project

[ERROR][2023-05-18 15:58:58] .../vim/lsp/rpc.lua:734    "rpc"   "/usr/lib/jvm/java-17-openjdk/bin/java" "stderr"        "WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector\n"
[WARN][2023-05-18 15:59:04] ...lsp/handlers.lua:137     "The language server jdtls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-05-18 15:59:04] ...lsp/handlers.lua:535    "May 18, 2023, 3:59:04 PM Command _java.reloadBundles.command not supported on client"

and after starting diagnostic on file showing

Java: filename.java is a non-project file, only syntax errors are reported
mfussenegger commented 1 year ago

Running :JdtCompile should show some more details if it can't build the project. See also the troubleshooting section.

Given that the other project works, this doesn't seem to be a client issue, but might be a server/gradle integration issue in which case you'll have to report this upstream in the eclipse.jdt.ls repo. (You could double check if you can get it working with the vscode java extension for good measure)