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