diff --git a/.gitignore b/.gitignore index 6bd4cbe..63212a2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,3 @@ 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 new file mode 100644 index 0000000..98705a7 --- /dev/null +++ b/nvim/ftplugin/java.lua @@ -0,0 +1,116 @@ +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 deleted file mode 100644 index 7691f74..0000000 --- a/nvim/lua/dzu/lsp/jdtls.lua +++ /dev/null @@ -1,42 +0,0 @@ -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 69a9752..1336ae2 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" }, - { nil, "jdtls" }, + { "jdtls", nil }, { "html", nil }, { "dockerls", nil }, } diff --git a/nvim/lua/dzu/plugins/lsp.lua b/nvim/lua/dzu/plugins/lsp.lua index a6c64f7..acef290 100644 --- a/nvim/lua/dzu/plugins/lsp.lua +++ b/nvim/lua/dzu/plugins/lsp.lua @@ -5,7 +5,6 @@ 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 deleted file mode 100644 index 4231beb..0000000 --- a/nvim/lua/dzu/plugins/nvim-java.lua +++ /dev/null @@ -1,56 +0,0 @@ -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, -} diff --git a/nvim/lua/dzu/plugins/tree-sitter.lua b/nvim/lua/dzu/plugins/tree-sitter.lua index 4be5159..d71e6f3 100644 --- a/nvim/lua/dzu/plugins/tree-sitter.lua +++ b/nvim/lua/dzu/plugins/tree-sitter.lua @@ -2,7 +2,6 @@ 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 d404625..77b9636 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_config = pcall(require, "nvim-treesitter.configs") + local is_ok, tree_sitter_configs = pcall(require, "nvim-treesitter.config") if not is_ok then vim.notify("couldn't find tree sitter") return @@ -15,10 +15,14 @@ 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", @@ -30,9 +34,10 @@ function M.setup() { "rust", "rs" }, "sql", "toml", - { "vim", nil }, + "vim", { "vimdoc", nil }, "xml", + { "ant", nil }, "nu", "java", "yaml", @@ -72,7 +77,7 @@ function M.setup() enable = true, -- false will disable the whole extension }, } - tree_sitter_config.setup(opts) + tree_sitter_configs.setup(opts) vim.cmd.TSUpdate()