From 2e7773cf4b0e2d226316b0f94dc85e41b2697ea2 Mon Sep 17 00:00:00 2001 From: joshashtondev Date: Tue, 1 Sep 2026 11:00:07 -0600 Subject: [PATCH] adding eclipse java support to neovim --- home/programs/nvim.nix | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/home/programs/nvim.nix b/home/programs/nvim.nix index 85f791f..eee3a89 100644 --- a/home/programs/nvim.nix +++ b/home/programs/nvim.nix @@ -7,6 +7,11 @@ vimAlias = true; defaultEditor = true; + extraPackages = with pkgs; [ + jdtls + jdk + ]; + initLua = '' vim.opt.number = true vim.opt.relativenumber = true @@ -85,6 +90,32 @@ delete = { text = "_" }, }, }) + + local lspconfig = require('lspconfig') + + -- Common keymaps to run when the Eclipse LSP attaches to a Java buffer + local on_attach = function(client, bufnr) + local opts = { buffer = bufnr, silent = true } + + -- Eclipse IDE core features mapped to Neovim actions + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, opts) + end + + -- Initialize the Eclipse JDTLS Server configuration + -- NixOS patches 'jdtls' wrapper script automatically to point to the correct binary paths + lspconfig.jdtls.setup({ + on_attach = on_attach, + cmd = { "jdtls" }, + root_dir = lspconfig.util.root_pattern(".git", "pom.xml", "build.gradle"), + }) ''; plugins = with pkgs.vimPlugins; [ @@ -95,6 +126,7 @@ { plugin = lualine-nvim; } { plugin = neocord; } { plugin = gitsigns-nvim; } + { plugin = nvim-lspconfig; } ]; }; }