neovim

Personal neovim configuration files
git clone git://gtms.dev/neovim
Log | Files | Refs

java.lua (4137B)


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