From 5567e71240eb0439a34c668858fbc33adad72ab9 Mon Sep 17 00:00:00 2001 From: Dzuchun Date: Fri, 2 Jan 2026 16:52:32 +0000 Subject: [PATCH 1/2] Improved java LSP support - not using `nvim-java` - figured out classpath --- .gitignore | 3 + nvim/ftplugin/java.lua | 116 ----------------------------- nvim/lua/dzu/lsp/jdtls.lua | 42 +++++++++++ nvim/lua/dzu/lsp/mason.lua | 2 +- nvim/lua/dzu/plugins/lsp.lua | 1 + nvim/lua/dzu/plugins/nvim-java.lua | 56 ++++++++++++++ 6 files changed, 103 insertions(+), 117 deletions(-) delete mode 100644 nvim/ftplugin/java.lua create mode 100644 nvim/lua/dzu/lsp/jdtls.lua create mode 100644 nvim/lua/dzu/plugins/nvim-java.lua diff --git a/.gitignore b/.gitignore index 63212a2..6bd4cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ mimeapps.list # htmlhint config, not a part of nvim config .htmlhintrc + +# jar for java testing +*.jar diff --git a/nvim/ftplugin/java.lua b/nvim/ftplugin/java.lua deleted file mode 100644 index 98705a7..0000000 --- a/nvim/ftplugin/java.lua +++ /dev/null @@ -1,116 +0,0 @@ -local home = os.getenv('HOME') - -local jdtls_dir = os.getenv("JDTLS_PATH") - -local root_dir = require('jdtls.setup').find_root({ 'gradlew', '.git', 'mvnw' }) -local workspace_folder = home .. "/.local/share/jdtls/" .. vim.fn.fnamemodify(root_dir, ":p:h:t") - -local config_dir = vim.api.nvim_exec2(":echo stdpath('config')", { output = true }).output - -local config = { - name = "jdtls", - -- `cmd` defines the executable to launch eclipse.jdt.ls. - -- `jdtls` must be available in $PATH and you must have Python3.9 for this to work. - -- - -- As alternative you could also avoid the `jdtls` wrapper and launch - -- eclipse.jdt.ls via the `java` executable - -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line - cmd = { - jdtls_dir .. '/bin/jdtls', - '-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', - '-Xmx1g', - '--add-modules=ALL-SYSTEM', - '--add-opens', 'java.base/java.util=ALL-UNNAMED', - '--add-opens', 'java.base/java.lang=ALL-UNNAMED', - - -- The jar file is located where jdtls was installed. This will need to be updated - -- to the location where you installed jdtls - '-jar', vim.fn.glob('/opt/homebrew/Cellar/jdtls/1.18.0/libexec/plugins/org.eclipse.equinox.launcher_*.jar'), - - -- The configuration for jdtls is also placed where jdtls was installed. This will - -- need to be updated depending on your environment - '-configuration', jdtls_dir .. 'config_linux', - - -- Use the workspace_folder defined above to store data for this project - '-data', workspace_folder, - }, - -- `root_dir` must point to the root of your project. - -- See `:help vim.fs.root` - root_dir = root_dir, - -- 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 = { - format = { - settings = { - -- Use Google Java style guidelines for formatting - -- To use, make sure to download the file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml - -- and place it in the ~/.local/share/eclipse directory - url = config_dir .. '/other/eclipse-java-google-style.xml', - profile = "GoogleStyle", - }, - }, - signatureHelp = { enabled = true }, - contentProvider = { preferred = 'fernflower' }, -- Use fernflower to decompile library code - -- Specify any completion options - completion = { - favoriteStaticMembers = { - -- ? - "org.junit.jupiter.api.Assertions.*", - "java.util.Objects.requireNonNull", - "java.util.Objects.requireNonNullElse", - }, - 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 = { - -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request - -- And search for `interface RuntimeOption` - -- The `name` is NOT arbitrary, but must match one of the elements from `enum ExecutionEnvironment` in the link above - runtimes = { - { - name = "JavaSE_21", - path = "/usr/lib/jvm/java-21-openjdk", - default = true, - }, - } - } - } - }, - -- This sets the `initializationOptions` sent to the language server - -- If you plan on using additional eclipse.jdt.ls plugins like java-debug - -- you'll need to set the `bundles` - -- - -- See https://codeberg.org/mfussenegger/nvim-jdtls#java-debug-installation - -- - -- If you don't plan on any eclipse.jdt.ls plugins you can remove this - init_options = { - bundles = {} - }, -} - -require('jdtls').start_or_attach(config) diff --git a/nvim/lua/dzu/lsp/jdtls.lua b/nvim/lua/dzu/lsp/jdtls.lua new file mode 100644 index 0000000..7691f74 --- /dev/null +++ b/nvim/lua/dzu/lsp/jdtls.lua @@ -0,0 +1,42 @@ +return { + settings = { + java = { + configuration = { + runtimes = { + { + name = "openjdk 21.0.9", + path = "/usr/lib/jvm/java-21-openjdk/", + default = true, + } + } + } + } + }, + capabilities = { + textDocument = { + completion = { + completionItem = { + commitCharactersSupport = false, + deprecatedSupport = true, + insertReplaceSupport = false, + insertTextModeSupport = {}, + labelDetailsSupport = true, + preselectSupport = true, + resolveSupport = { + properties = { "documentation", "additionalTextEdits", "insertTextFormat", "insertTextMode", "command" } + }, + snippetSupport = true, + tagSupport = {} + }, + completionList = { + itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" } + }, + contextSupport = true, + dynamicRegistration = false, + insertTextMode = 1 + } + } + }, + init_options = {}, + root_markers = { ".classpath" }, +} diff --git a/nvim/lua/dzu/lsp/mason.lua b/nvim/lua/dzu/lsp/mason.lua index 1336ae2..69a9752 100644 --- a/nvim/lua/dzu/lsp/mason.lua +++ b/nvim/lua/dzu/lsp/mason.lua @@ -20,7 +20,7 @@ local servers = { { "clangd", "clangd" }, { "lua_ls", "lua_ls" }, { "tinymist", "tinymist" }, - { "jdtls", nil }, + { nil, "jdtls" }, { "html", nil }, { "dockerls", nil }, } diff --git a/nvim/lua/dzu/plugins/lsp.lua b/nvim/lua/dzu/plugins/lsp.lua index acef290..a6c64f7 100644 --- a/nvim/lua/dzu/plugins/lsp.lua +++ b/nvim/lua/dzu/plugins/lsp.lua @@ -5,6 +5,7 @@ return { "neovim/nvim-lspconfig", -- lsp completions "hrsh7th/cmp-nvim-lsp", + 'nvim-java/nvim-java', }, lazy = false, } diff --git a/nvim/lua/dzu/plugins/nvim-java.lua b/nvim/lua/dzu/plugins/nvim-java.lua new file mode 100644 index 0000000..4231beb --- /dev/null +++ b/nvim/lua/dzu/plugins/nvim-java.lua @@ -0,0 +1,56 @@ +return { + 'nvim-java/nvim-java', + config = function() + require('java').setup({ + -- Startup checks + checks = { + nvim_version = true, -- Check Neovim version + nvim_jdtls_conflict = true, -- Check for nvim-jdtls conflict + }, + + -- JDTLS configuration + jdtls = { + version = '1.54.0', + }, + + -- Extensions + lombok = { + enable = false, + version = '1.18.40', + }, + + java_test = { + enable = false, + version = '0.40.1', + }, + + java_debug_adapter = { + enable = false, + version = '0.58.2', + }, + + spring_boot_tools = { + enable = false, + version = '1.55.1', + }, + + -- JDK installation + jdk = { + auto_install = false, + version = '17', + }, + + -- Logging + log = { + use_console = false, + use_file = true, + level = 'info', + log_file = vim.fn.stdpath('state') .. '/nvim-java.log', + max_lines = 1000, + show_location = false, + }, + }) + -- vim.lsp.enable('jdtls') + end, + lazy = false, +} From 46b650dd73c633379a68813f4cc5380840761acb Mon Sep 17 00:00:00 2001 From: Dzuchun Date: Fri, 2 Jan 2026 16:55:52 +0000 Subject: [PATCH 2/2] fix: moved back to `master` branch of tree-sitter --- nvim/lua/dzu/plugins/tree-sitter.lua | 1 + nvim/lua/dzu/syntax.lua | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/nvim/lua/dzu/plugins/tree-sitter.lua b/nvim/lua/dzu/plugins/tree-sitter.lua index d71e6f3..4be5159 100644 --- a/nvim/lua/dzu/plugins/tree-sitter.lua +++ b/nvim/lua/dzu/plugins/tree-sitter.lua @@ -2,6 +2,7 @@ return { "nvim-treesitter/nvim-treesitter", + branch = "master", build = ':TSUpdate', lazy = false, } diff --git a/nvim/lua/dzu/syntax.lua b/nvim/lua/dzu/syntax.lua index 77b9636..d404625 100644 --- a/nvim/lua/dzu/syntax.lua +++ b/nvim/lua/dzu/syntax.lua @@ -1,7 +1,7 @@ local M = {} function M.setup() - local is_ok, tree_sitter_configs = pcall(require, "nvim-treesitter.config") + local is_ok, tree_sitter_config = pcall(require, "nvim-treesitter.configs") if not is_ok then vim.notify("couldn't find tree sitter") return @@ -15,14 +15,10 @@ function M.setup() { "dockerfile", nil }, "fish", { "gitignore", "gitignore" }, - -- { "diff", nil }, - -- { "git_rebase", nil }, - -- { "gitcommit", "git/COMMIT_EDITMSG" }, { "haskell", "hs" }, "html", { "javascript", "js" }, { "typescript", "ts" }, - "jsx", "tsx", "json", "lua", @@ -34,10 +30,9 @@ function M.setup() { "rust", "rs" }, "sql", "toml", - "vim", + { "vim", nil }, { "vimdoc", nil }, "xml", - { "ant", nil }, "nu", "java", "yaml", @@ -77,7 +72,7 @@ function M.setup() enable = true, -- false will disable the whole extension }, } - tree_sitter_configs.setup(opts) + tree_sitter_config.setup(opts) vim.cmd.TSUpdate()