mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1k stars 62 forks source link

Weird coloration happens with nvim-jdtls + tree-sitter #574

Closed Matsuuu closed 9 months ago

Matsuuu commented 9 months ago

LSP client configuration

-- vim.g.java_highlight_all = 1

--require 'rcfiles.plugins.nvim_jdtls-settings'
-- Had to move this here because it was not loading on new files.

-- If you started neovim within `~/dev/xy/project-1` this would resolve to `project-1`
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')

local workspace_dir = '/home/matsu/workspace/' .. project_name
--                                               ^^
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
local config = {
  -- The command that starts the language server
  -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
  cmd = {

    '/usr/bin/jdtls'
    -- '/home/matsu/Tools/jdtls/bin/jdtls'

    -- 'java', -- or '/path/to/java11_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',
    ----'--add-modules', 'jdk.incubator.foreign',
    ----'--add-modules', 'jdk.incubator.vector',

    ---- 💀
    -- '-jar', vim.fn.glob('/home/matsu/Tools/jdtls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar'),
    --     -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       ^^^^^^^^^^^^^^
    --     -- Must point to the                                                     Change this to
    --     -- eclipse.jdt.ls installation                                           the actual version

    ---- 💀
    --'-configuration', '/home/matsu/Tools/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/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'}),

  -- 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 = {
        configuration = {
        },
        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.*",
                "java.awt.*",
                "jdk.*",
                "sun.*",
            },
        };
    }
  },
  init_options = {
    bundles = {
    }
  },

  on_attach = function(client, bufnr) 
    local jdtls = require('jdtls')
    jdtls.setup_dap({ hotcodereplace = 'auto' }) 
    jdtls.setup.add_commands()
  end,

}

local bundles = {
    "/home/matsu/Tools/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-0.34.0.jar"
}

-- vim.fn.glob("/home/matsu/Tools/vscode-java-test/server/*.jar")
vim.list_extend(bundles, vim.split(vim.fn.glob("/home/matsu/Tools/vscode-java-test/server/*.jar"), "\n"))
config['init_options'] = {
  bundles = bundles;
}

-- This starts a new client & server,
-- or attaches to an existing client & server depending on the `root_dir`.
require('jdtls').start_or_attach(config)

Eclipse.jdt.ls version

No response

Steps to Reproduce

Video attached.

Open neovim with jdtls enabled. After LSP has setup and connected, color scheme on some elements changes

https://github.com/mfussenegger/nvim-jdtls/assets/16068444/e4cf95c0-6c1a-4577-8e88-22ac3b473f39

Expected Result

Color scheme doesn't change

Actual Result

Color scheme on e.g. Import paths changes

mfussenegger commented 9 months ago

That's semantic token highlighting that's part of neovim core. See :help lsp-semantic-highlight

Nothing specific to nvim-jdtls.

Matsuuu commented 9 months ago

Ah, thank you for clarification, and sorry!