|
|
|
@ -5,9 +5,7 @@ local SDKMAN_DIR = os.getenv("SDKMAN_DIR")
|
|
|
|
|
local lsp = require("lsp")
|
|
|
|
|
local jdtls = require("jdtls")
|
|
|
|
|
|
|
|
|
|
-- File types that signify a Java project's root directory. This will be
|
|
|
|
|
-- used by eclipse to determine what constitutes a workspace
|
|
|
|
|
local root_markers = { "gradlew", "mvnw", ".git" }
|
|
|
|
|
local root_markers = { "gradlew", "mvnw", ".git", "pom.xml", "build.gradle" }
|
|
|
|
|
local root_dir = require("jdtls.setup").find_root(root_markers)
|
|
|
|
|
|
|
|
|
|
-- eclipse.jdt.ls stores project specific data within a folder. If you are working
|
|
|
|
@ -16,15 +14,26 @@ local root_dir = require("jdtls.setup").find_root(root_markers)
|
|
|
|
|
-- current project found using the root_marker as the folder for project specific data.
|
|
|
|
|
local workspace_folder = HOME .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
|
|
|
|
|
|
|
|
|
|
-- Helper function for creating keymaps
|
|
|
|
|
function nnoremap(rhs, lhs, bufopts, desc)
|
|
|
|
|
local bundles = {}
|
|
|
|
|
local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/")
|
|
|
|
|
vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n"))
|
|
|
|
|
vim.list_extend(
|
|
|
|
|
bundles,
|
|
|
|
|
vim.split(
|
|
|
|
|
vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"),
|
|
|
|
|
"\n"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
local function nnoremap(rhs, lhs, bufopts, desc)
|
|
|
|
|
bufopts.desc = desc
|
|
|
|
|
vim.keymap.set("n", rhs, lhs, bufopts)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- The on_attach function is used to set key maps after the language server
|
|
|
|
|
-- attaches to the current buffer
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
|
require("jdtls").setup_dap({ hotcodereplace = "auto" })
|
|
|
|
|
require("jdtls.dap").setup_dap_main_class_configs()
|
|
|
|
|
require("jdtls.setup").add_commands()
|
|
|
|
|
lsp.default_config.on_attach(client, bufnr)
|
|
|
|
|
|
|
|
|
|
-- Regular Neovim LSP client keymappings
|
|
|
|
@ -45,36 +54,35 @@ local on_attach = function(client, bufnr)
|
|
|
|
|
[[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]],
|
|
|
|
|
{ noremap = true, silent = true, buffer = bufnr, desc = "Extract method" }
|
|
|
|
|
)
|
|
|
|
|
nnoremap("<leader>tc", jdtls.test_class, bufopts, "Test class (DAP)")
|
|
|
|
|
nnoremap("<leader>tm", jdtls.test_nearest_method, bufopts, "Test method (DAP)")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local config = {
|
|
|
|
|
flags = {
|
|
|
|
|
debounce_text_changes = 80,
|
|
|
|
|
allow_incremental_sync = true,
|
|
|
|
|
},
|
|
|
|
|
on_attach = on_attach, -- We pass our on_attach keybindings to the configuration map
|
|
|
|
|
root_dir = root_dir, -- Set the root directory to our found root_marker
|
|
|
|
|
-- Here you can configure eclipse.jdt.ls specific settings
|
|
|
|
|
-- These are defined by the eclipse.jdt.ls project and will be passed to eclipse when starting.
|
|
|
|
|
-- 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
|
|
|
|
|
on_attach = on_attach,
|
|
|
|
|
root_dir = root_dir,
|
|
|
|
|
init_options = {
|
|
|
|
|
bundles = bundles,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
-- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
|
|
|
|
|
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
|
|
|
|
|
-- https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
|
|
|
|
|
url = "/.local/share/eclipse/eclipse-java-google-style.xml",
|
|
|
|
|
profile = "GoogleStyle",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
implementationsCodeLens = { enabled = true },
|
|
|
|
|
referenceCodeLens = { enabled = true },
|
|
|
|
|
signatureHelp = { enabled = true },
|
|
|
|
|
contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code
|
|
|
|
|
-- Specify any completion options
|
|
|
|
|
completion = {
|
|
|
|
|
maxResults = 20,
|
|
|
|
|
maxResults = 30,
|
|
|
|
|
postfix = { enabled = true },
|
|
|
|
|
favoriteStaticMembers = {
|
|
|
|
|
"org.hamcrest.MatcherAssert.assertThat",
|
|
|
|
@ -93,6 +101,13 @@ local config = {
|
|
|
|
|
"sun.*",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- LSP Related
|
|
|
|
|
implementationsCodeLens = { enabled = true },
|
|
|
|
|
referenceCodeLens = { enabled = true },
|
|
|
|
|
signatureHelp = { enabled = true },
|
|
|
|
|
inlayHints = {
|
|
|
|
|
parameterNames = { enabled = true },
|
|
|
|
|
},
|
|
|
|
|
-- Specify any options for organizing imports
|
|
|
|
|
sources = {
|
|
|
|
|
organizeImports = {
|
|
|
|
@ -100,11 +115,14 @@ local config = {
|
|
|
|
|
staticStarThreshold = 9999,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
maven = {
|
|
|
|
|
downloadSources = true,
|
|
|
|
|
updateSnapshots = true,
|
|
|
|
|
},
|
|
|
|
|
-- On Save Cleanup
|
|
|
|
|
cleanup = {
|
|
|
|
|
actionsOnSave = {
|
|
|
|
|
"addOverride",
|
|
|
|
|
"qualifyStaticMembers",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- How code generation should act
|
|
|
|
@ -117,11 +135,8 @@ local config = {
|
|
|
|
|
},
|
|
|
|
|
useBlocks = true,
|
|
|
|
|
},
|
|
|
|
|
-- If you are developing in projects with different Java versions, you need
|
|
|
|
|
-- to tell eclipse.jdt.ls to use the location of the JDK for your Java version
|
|
|
|
|
-- 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
|
|
|
|
|
-- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
|
|
|
|
|
-- `interface RuntimeOption`
|
|
|
|
|
configuration = {
|
|
|
|
|
maven = {
|
|
|
|
|
userSettings = HOME .. "/.m2/settings.xml",
|
|
|
|
@ -143,11 +158,8 @@ local config = {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- cmd is the command that starts the language server. Whatever is placed
|
|
|
|
|
-- here is what is passed to the command line to execute jdtls.
|
|
|
|
|
-- Note that eclipse.jdt.ls must be started with a Java version of 17 or higher
|
|
|
|
|
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
|
|
|
|
|
-- for the full list of options
|
|
|
|
|
cmd = {
|
|
|
|
|
SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java",
|
|
|
|
|
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
|
|
|
@ -166,18 +178,12 @@ local config = {
|
|
|
|
|
-- .. HOME
|
|
|
|
|
-- .. "/.local/share/eclipse/lombok.jar",
|
|
|
|
|
|
|
|
|
|
-- The jar file is located where jdtls was installed. This will need to be updated
|
|
|
|
|
-- to the location where you installed jdtls
|
|
|
|
|
"-jar",
|
|
|
|
|
-- HOME .. "/.local/share/eclipse.jdt.ls/bin",
|
|
|
|
|
vim.fn.glob(HOME .. "/.local/share/eclipse.jdt.ls/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",
|
|
|
|
|
HOME .. "/.local/share/eclipse.jdt.ls/config_linux",
|
|
|
|
|
|
|
|
|
|
-- Use the workspace_folder defined above to store data for this project
|
|
|
|
|
"-data",
|
|
|
|
|
workspace_folder,
|
|
|
|
|
},
|
|
|
|
|