eclipse-jdtls / eclipse.jdt.ls

Java language server
1.76k stars 392 forks source link

Android project has no code suggestions #3284

Open codewithtoucans opened 2 hours ago

codewithtoucans commented 2 hours ago

In Android project how can I get android code suggestions?

OS: windows 10 Gradle: 6.5 JDK: installed 8, 11 ,17 IDE: Neovim 0.10.1

I set JAVA_HOME and ANDROID_HOME in the system variables, but after building the project and install dependences, no errors, I only get basic JDK code suggestions and no Android code suggestions. Do I need to make any special settings in my lua file, or is there any other configuration needed? I'm a newbie in this area and would appreciate any help! Thanks!

my config

config = {
        -- set jdtls server settings
        jdtls = {
          function()
            -- use this function notation to build some variables
            local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
            local root_dir = require("jdtls.setup").find_root(root_markers)
            -- calculate workspace dir
            local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
            local workspace_dir = vim.fn.stdpath "data" .. "/site/java/workspace-root/" .. project_name
            os.execute("mkdir " .. workspace_dir)
            -- get the mason install path
            local install_path = require("mason-registry").get_package("jdtls"):get_install_path()
            -- get the current OS
            local os
            if vim.fn.has "macunix" then
              os = "mac"
            elseif vim.fn.has "win32" then
              os = "win"
            else
              os = "linux"
            end
            -- return the server config
            return {
              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",
                "-javaagent:" .. install_path .. "/lombok.jar",
                "-Xms1g",
                "--add-modules=ALL-SYSTEM",
                "--add-opens",
                "java.base/java.util=ALL-UNNAMED",
                "--add-opens",
                "java.base/java.lang=ALL-UNNAMED",
                "-jar",
                vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"),
                "-configuration",
                install_path .. "/config_" .. os,
                "-data",
                workspace_dir,
              },
              root_dir = root_dir,
            }
          end,
        },
      },
codewithtoucans commented 2 hours ago

If someone could help me, I would be extremely grateful. 😃