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

Highlights seem to be overridden #397

Closed mrdgo closed 1 year ago

mrdgo commented 1 year ago

LSP client configuration

local jdtls = require("jdtls")
local root_markers = { "gradlew", ".git" }
local root_dir = require("jdtls.setup").find_root(root_markers)
local home = os.getenv("HOME")
local workspace_folder = home .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
-- :help vim.lsp.start_client` for an overview of the supported `config` options.

local bundles = {
    vim.fn.glob("/opt/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar"),
}

vim.list_extend(bundles, vim.split(vim.fn.glob("/opt/vscode-java-test/server/*.jar"), "\n"))
-- vim.list_extend(bundles, vim.split(vim.fn.glob("/home/maxim/downloads/extensions/jars/*.jar"), "\n"))

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",
        "-Xms1g",
        "--add-modules=ALL-SYSTEM",
        "--add-opens",
        "java.base/java.util=ALL-UNNAMED",
        "--add-opens",
        "java.base/java.lang=ALL-UNNAMED",
        "-javaagent:/home/maxim/.config/nvim/config/lombok.jar",
        "-jar",
        "/usr/share/java/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar",
        "-configuration",
        "/usr/share/java/jdtls/config_linux",
        "-data",
        workspace_folder,
    },
    root_dir = jdtls.setup.find_root({ ".git", "mvnw", "gradlew" }),
    settings = {
        java = {
            format = {
                settings = {
                    url = " https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
                },
            },
        },
    },
    init_options = {
        bundles = bundles,
    },
    on_attach = function()
        require("lsp_on_attach").on_attach()

        jdtls.setup_dap({ hotcodereplace = "auto" })
        require("dap").configurations.java = {
            {
                type = "server",
                request = "attach",
                name = "Debug (Attach) - Remote",
                hostName = "127.0.0.1",
                port = 5005,
            },
        }
        jdtls.setup.add_commands()

        local jdt_maps = {
            oi = jdtls.organize_imports,
            ct = jdtls.test_class,
            nt = jdtls.test_nearest_method,
            -- e = "extract_variable(true)"
            -- m = "extract_method(true)"
        }

        -- Java specific
        for key, cmd in pairs(jdt_maps) do
            vim.keymap.set("n", "<Leader>s" .. key, cmd, { noremap = false, silent = true })
        end
    end,
}

Eclipse.jdt.ls version

1.18.0-2

Steps to Reproduce

Open a java file.

Expected Result

I use treesitter for syntax highlighting and it works fine: image

Actual Result

As soon as jdtls started, the highlights become ... much more boring: image

Most highlights have the same color. The syntax has improved, I like how the imports separate package names from class names. However, I don't find any documentation on how to configure these.

I understand, if this is not in the scope of this plugin. Still, if you have any idea where I can find docs - any help appreciated!

mfussenegger commented 1 year ago

This is due to LSP semantic tokens which was recently merged in neovim. See :h lsp-semantic_tokens and https://github.com/neovim/neovim/pull/21100

You could tune your color scheme to support the highlight groups. In latest neovim master you can use the :Inspect command to get information about what groups are used by a word/expression under the cursor:

image