|
|
|
@ -5,15 +5,6 @@ local SDKMAN_DIR = os.getenv("SDKMAN_DIR")
|
|
|
|
|
local lsp = require("lsp")
|
|
|
|
|
local jdtls = require("jdtls")
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
-- with multiple different projects, each project must use a dedicated data directory.
|
|
|
|
|
-- This variable is used to configure eclipse to use the directory name of the
|
|
|
|
|
-- 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")
|
|
|
|
|
|
|
|
|
|
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"))
|
|
|
|
@ -58,139 +49,137 @@ local on_attach = function(client, bufnr)
|
|
|
|
|
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,
|
|
|
|
|
root_dir = root_dir,
|
|
|
|
|
init_options = {
|
|
|
|
|
bundles = bundles,
|
|
|
|
|
},
|
|
|
|
|
function M.make_jdtls_config(root_dir, workspace_folder)
|
|
|
|
|
return {
|
|
|
|
|
flags = {
|
|
|
|
|
debounce_text_changes = 80,
|
|
|
|
|
allow_incremental_sync = true,
|
|
|
|
|
},
|
|
|
|
|
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 = {
|
|
|
|
|
-- https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
|
|
|
|
|
url = "/.local/share/eclipse/eclipse-java-google-style.xml",
|
|
|
|
|
profile = "GoogleStyle",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code
|
|
|
|
|
-- Specify any completion options
|
|
|
|
|
completion = {
|
|
|
|
|
maxResults = 30,
|
|
|
|
|
postfix = { enabled = true },
|
|
|
|
|
favoriteStaticMembers = {
|
|
|
|
|
"org.hamcrest.MatcherAssert.assertThat",
|
|
|
|
|
"org.hamcrest.Matchers.*",
|
|
|
|
|
"org.hamcrest.CoreMatchers.*",
|
|
|
|
|
"org.junit.jupiter.api.Assertions.*",
|
|
|
|
|
"java.util.Objects.requireNonNull",
|
|
|
|
|
"java.util.Objects.requireNonNullElse",
|
|
|
|
|
"org.mockito.Mockito.*",
|
|
|
|
|
},
|
|
|
|
|
filteredTypes = {
|
|
|
|
|
"com.sun.*",
|
|
|
|
|
"io.micrometer.shaded.*",
|
|
|
|
|
"java.awt.*",
|
|
|
|
|
"jdk.*",
|
|
|
|
|
"sun.*",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- LSP Related
|
|
|
|
|
implementationsCodeLens = { enabled = true },
|
|
|
|
|
referenceCodeLens = { enabled = true },
|
|
|
|
|
signatureHelp = { enabled = true },
|
|
|
|
|
inlayHints = {
|
|
|
|
|
parameterNames = { enabled = true },
|
|
|
|
|
},
|
|
|
|
|
-- Specify any options for organizing imports
|
|
|
|
|
sources = {
|
|
|
|
|
organizeImports = {
|
|
|
|
|
starThreshold = 9999,
|
|
|
|
|
staticStarThreshold = 9999,
|
|
|
|
|
-- https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
|
|
|
|
|
settings = {
|
|
|
|
|
java = {
|
|
|
|
|
format = {
|
|
|
|
|
settings = {
|
|
|
|
|
-- https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
|
|
|
|
|
url = "/.local/share/eclipse/eclipse-java-google-style.xml",
|
|
|
|
|
profile = "GoogleStyle",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
maven = {
|
|
|
|
|
downloadSources = true,
|
|
|
|
|
updateSnapshots = true,
|
|
|
|
|
},
|
|
|
|
|
-- On Save Cleanup
|
|
|
|
|
cleanup = {
|
|
|
|
|
actionsOnSave = {
|
|
|
|
|
"addOverride",
|
|
|
|
|
contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code
|
|
|
|
|
-- Specify any completion options
|
|
|
|
|
completion = {
|
|
|
|
|
maxResults = 30,
|
|
|
|
|
postfix = { enabled = true },
|
|
|
|
|
favoriteStaticMembers = {
|
|
|
|
|
"org.hamcrest.MatcherAssert.assertThat",
|
|
|
|
|
"org.hamcrest.Matchers.*",
|
|
|
|
|
"org.hamcrest.CoreMatchers.*",
|
|
|
|
|
"org.junit.jupiter.api.Assertions.*",
|
|
|
|
|
"java.util.Objects.requireNonNull",
|
|
|
|
|
"java.util.Objects.requireNonNullElse",
|
|
|
|
|
"org.mockito.Mockito.*",
|
|
|
|
|
},
|
|
|
|
|
filteredTypes = {
|
|
|
|
|
"com.sun.*",
|
|
|
|
|
"io.micrometer.shaded.*",
|
|
|
|
|
"java.awt.*",
|
|
|
|
|
"jdk.*",
|
|
|
|
|
"sun.*",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- How code generation should act
|
|
|
|
|
codeGeneration = {
|
|
|
|
|
toString = {
|
|
|
|
|
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
|
|
|
|
|
-- LSP Related
|
|
|
|
|
implementationsCodeLens = { enabled = true },
|
|
|
|
|
referenceCodeLens = { enabled = true },
|
|
|
|
|
signatureHelp = { enabled = true },
|
|
|
|
|
inlayHints = {
|
|
|
|
|
parameterNames = { enabled = true },
|
|
|
|
|
},
|
|
|
|
|
hashCodeEquals = {
|
|
|
|
|
useJava7Objects = true,
|
|
|
|
|
-- Specify any options for organizing imports
|
|
|
|
|
sources = {
|
|
|
|
|
organizeImports = {
|
|
|
|
|
starThreshold = 9999,
|
|
|
|
|
staticStarThreshold = 9999,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
useBlocks = true,
|
|
|
|
|
},
|
|
|
|
|
-- 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",
|
|
|
|
|
downloadSources = true,
|
|
|
|
|
updateSnapshots = true,
|
|
|
|
|
},
|
|
|
|
|
runtimes = {
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-17",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/17.0.5-amzn",
|
|
|
|
|
-- On Save Cleanup
|
|
|
|
|
cleanup = {
|
|
|
|
|
actionsOnSave = {
|
|
|
|
|
"addOverride",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-11",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/11.0.18-amzn",
|
|
|
|
|
},
|
|
|
|
|
-- How code generation should act
|
|
|
|
|
codeGeneration = {
|
|
|
|
|
toString = {
|
|
|
|
|
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}",
|
|
|
|
|
},
|
|
|
|
|
hashCodeEquals = {
|
|
|
|
|
useJava7Objects = true,
|
|
|
|
|
},
|
|
|
|
|
useBlocks = true,
|
|
|
|
|
},
|
|
|
|
|
-- 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",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-1.8",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/8.0.362-amzn",
|
|
|
|
|
runtimes = {
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-17",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/17.0.5-amzn",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-11",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/11.0.18-amzn",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "JavaSE-1.8",
|
|
|
|
|
path = SDKMAN_DIR .. "/candidates/java/8.0.362-amzn",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
-- 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
|
|
|
|
|
cmd = {
|
|
|
|
|
SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java",
|
|
|
|
|
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
|
|
|
|
"-Dosgi.bundles.defaultStartLevel=4",
|
|
|
|
|
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
|
|
|
|
"-Dlog.protocol=true",
|
|
|
|
|
"-Dlog.level=ALL",
|
|
|
|
|
"-Xmx4g",
|
|
|
|
|
"--add-modules=ALL-SYSTEM",
|
|
|
|
|
"--add-opens",
|
|
|
|
|
"java.base/java.util=ALL-UNNAMED",
|
|
|
|
|
"--add-opens",
|
|
|
|
|
"java.base/java.lang=ALL-UNNAMED",
|
|
|
|
|
-- If you use lombok, download the lombok jar and place it in ~/.local/share/eclipse
|
|
|
|
|
-- "-javaagent:"
|
|
|
|
|
-- .. HOME
|
|
|
|
|
-- .. "/.local/share/eclipse/lombok.jar",
|
|
|
|
|
|
|
|
|
|
"-jar",
|
|
|
|
|
vim.fn.glob(HOME .. "/.local/share/eclipse.jdt.ls/plugins/org.eclipse.equinox.launcher_*.jar"),
|
|
|
|
|
-- 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
|
|
|
|
|
cmd = {
|
|
|
|
|
SDKMAN_DIR .. "/candidates/java/17.0.5-amzn/bin/java",
|
|
|
|
|
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
|
|
|
|
"-Dosgi.bundles.defaultStartLevel=4",
|
|
|
|
|
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
|
|
|
|
"-Dlog.protocol=true",
|
|
|
|
|
"-Dlog.level=ALL",
|
|
|
|
|
"-Xmx4g",
|
|
|
|
|
"--add-modules=ALL-SYSTEM",
|
|
|
|
|
"--add-opens",
|
|
|
|
|
"java.base/java.util=ALL-UNNAMED",
|
|
|
|
|
"--add-opens",
|
|
|
|
|
"java.base/java.lang=ALL-UNNAMED",
|
|
|
|
|
-- If you use lombok, download the lombok jar and place it in ~/.local/share/eclipse
|
|
|
|
|
-- "-javaagent:"
|
|
|
|
|
-- .. HOME
|
|
|
|
|
-- .. "/.local/share/eclipse/lombok.jar",
|
|
|
|
|
|
|
|
|
|
"-configuration",
|
|
|
|
|
HOME .. "/.local/share/eclipse.jdt.ls/config_linux",
|
|
|
|
|
"-jar",
|
|
|
|
|
vim.fn.glob(HOME .. "/.local/share/eclipse.jdt.ls/plugins/org.eclipse.equinox.launcher_*.jar"),
|
|
|
|
|
|
|
|
|
|
"-data",
|
|
|
|
|
workspace_folder,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
"-configuration",
|
|
|
|
|
HOME .. "/.local/share/eclipse.jdt.ls/config_linux",
|
|
|
|
|
|
|
|
|
|
function M.make_jdtls_config()
|
|
|
|
|
return config
|
|
|
|
|
"-data",
|
|
|
|
|
workspace_folder,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|
|
|
|
|