From 85be35d962d1b9c74eca871d9deb7400a8acdf35 Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Wed, 11 Jan 2023 16:16:04 -0600 Subject: [PATCH] added java LS support (finally!) --- neovim/.config/nvim/ftplugin/java.lua | 82 +++++++++++++++++++++++++++ neovim/.config/nvim/lua/packages.lua | 4 +- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 neovim/.config/nvim/ftplugin/java.lua diff --git a/neovim/.config/nvim/ftplugin/java.lua b/neovim/.config/nvim/ftplugin/java.lua new file mode 100644 index 0000000..f46707f --- /dev/null +++ b/neovim/.config/nvim/ftplugin/java.lua @@ -0,0 +1,82 @@ +local opts = { + cmd = {}, + settings = { + java = { + signatureHelp = { enabled = true }, + completion = { + favoriteStaticMembers = {}, + 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}}", + }, + useBlocks = true, + }, + configuration = { + runtimes = { + { + name = "JavaSE-1.8", + path = "/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home", + default = true, + }, + { + name = "JavaSE-17", + path = "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home", + }, + { + name = "JavaSE-19", + path = "/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home", + }, + }, + }, + }, + }, +} +local jdtls_config = opts +local pkg_status, jdtls = pcall(require,"jdtls") +if not pkg_status then + vim.notify("unable to load nvim-jdtls", "error") + return {} +end + +-- local jdtls_path = vim.fn.stdpath("data") .. "/mason/packages/jdtls" +local jdtls_bin = vim.fn.stdpath("data") .. "/mason/bin/jdtls" + +local root_markers = { ".gradle", "gradlew", ".git" } +local root_dir = jdtls.setup.find_root(root_markers) +local home = os.getenv("HOME") +local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t") +local workspace_dir = home .. "/.cache/jdtls/workspace/" .. project_name + +opts.cmd = { + jdtls_bin, + "-data", + workspace_dir, +} + + +local on_attach = function(client, bufnr) + jdtls.setup.add_commands() -- important to ensure you can update configs when build is updated + -- if you setup DAP according to https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration you can uncomment below + -- jdtls.setup_dap({ hotcodereplace = "auto" }) + -- jdtls.dap.setup_dap_main_class_configs() + + -- you may want to also run your generic on_attach() function used by your LSP config +end + +opts.on_attach = on_attach +opts.capabilities = vim.lsp.protocol.make_client_capabilities() +jdtls.start_or_attach(jdtls_config) diff --git a/neovim/.config/nvim/lua/packages.lua b/neovim/.config/nvim/lua/packages.lua index b1e94a3..dd9dcfe 100644 --- a/neovim/.config/nvim/lua/packages.lua +++ b/neovim/.config/nvim/lua/packages.lua @@ -62,8 +62,8 @@ return require('packer').startup(function(use) require('LSPconfig') end }, - {'simrat39/rust-tools.nvim', - } + {'simrat39/rust-tools.nvim',}, + {'mfussenegger/nvim-jdtls',}, } use {'hrsh7th/nvim-cmp',