java.lua (4289B)
1 local set = vim.opt_local 2 set.shiftwidth = 4 3 4 -- If you started neovim within `~/dev/xy/project-1` this would resolve to `project-1` 5 local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') 6 local root_dir = vim.fs.root(0, { ".git", "pom.xml", "mvnw", "gradlew" }) 7 8 local bundles = { 9 -- vim.env.MASON .. "/share/java-debug-adapter/com.microsoft.java.test.plugin.jar", 10 vim.env.MASON .. "/share/java-test/com.microsoft.java.test.plugin.jar" 11 } 12 -- vim.list_extend(bundles, 13 -- vim.split(vim.fn.glob(vim.env.MASON .. "/share/java-debug-adapter/*.jar", true), "\n")) 14 -- vim.list_extend(bundles, 15 -- vim.split(vim.fn.glob(vim.env.MASON .. "/share/java-test/com.microsoft.java.test.plugin.jar", true), "\n")) 16 -- See `:help vim.lsp.start_client` for an overview of the supported `config` options. 17 local config = { 18 -- The command that starts te language server 19 -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line 20 cmd = { 21 22 -- 💀 23 'java', -- or '/path/to/java17_or_newer/bin/java' 24 -- depends on if `java` is in your $PATH env variable and if it points to the right version. 25 26 '-Declipse.application=org.eclipse.jdt.ls.core.id1', 27 '-Dosgi.bundles.defaultStartLevel=4', 28 '-Declipse.product=org.eclipse.jdt.ls.core.product', 29 '-Dlog.protocol=true', 30 '-Dlog.level=ALL', 31 '-Xmx1g', 32 '--add-modules=ALL-SYSTEM', 33 '--add-opens', 'java.base/java.util=ALL-UNNAMED', 34 '--add-opens', 'java.base/java.lang=ALL-UNNAMED', 35 36 -- repository/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar 37 "-javaagent:" .. 38 vim.env.XDG_DATA_HOME .. 39 "/maven/repository/org/projectlombok/lombok/1.18.34/lombok-1.18.34.jar", 40 41 -- 💀 42 '-jar', vim.fn.glob(vim.env.MASON .. '/share/jdtls/plugins/org.eclipse.equinox.launcher_*.jar', true), 43 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ 44 -- Must point to the Change this to 45 -- eclipse.jdt.ls installation the actual version 46 47 48 -- 💀 49 '-configuration', vim.env.MASON .. '/share/jdtls/config', 50 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^ 51 -- Must point to the Change to one of `linux`, `win` or `mac` 52 -- eclipse.jdt.ls installation Depending on your system. 53 54 55 -- 💀 56 -- See `data directory configuration` section in the README 57 '-data', vim.env.XDG_CACHE_HOME .. '/jdtls/' .. project_name 58 }, 59 60 -- 💀 61 -- This is the default if not provided, you can remove it. Or adjust as needed. 62 -- One dedicated LSP server & client will be started per unique root_dir 63 -- 64 -- vim.fs.root requires Neovim 0.10. 65 -- If you're using an earlier version, use: require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'}), 66 root_dir = root_dir, 67 68 -- Here you can configure eclipse.jdt.ls specific settings 69 -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request 70 -- for a list of options 71 settings = { 72 -- java.configuration.maven.userSettings 73 java = { 74 configuration = { 75 jdt = { 76 ls = { 77 lombokSupport = { enabled = false } 78 } 79 }, 80 maven = { 81 userSettings = root_dir .. '/maven-settings-local.xml' 82 } 83 } 84 } 85 }, 86 87 -- Language server `initializationOptions` 88 -- You need to extend the `bundles` with paths to jar files 89 -- if you want to use additional eclipse.jdt.ls plugins. 90 -- 91 -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation 92 -- 93 -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this 94 init_options = { 95 bundles = bundles, 96 }, 97 } 98 -- This starts a new client & server, 99 -- or attaches to an existing client & server depending on the `root_dir`. 100 require('jdtls').start_or_attach(config) 101 102 vim.api.nvim_create_user_command('JdtTestClass', require 'jdtls'.test_class, { desc = 'Test Class' }) 103 vim.api.nvim_create_user_command('JdtTestMethod', require 'jdtls'.test_nearest_method, { desc = 'Test Nearest Method' }) 104 vim.api.nvim_create_user_command('JdtTestPick', require 'jdtls'.pick_test, { desc = 'Pick Test' })