mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 08:35:48 +02:00
dap testing
This commit is contained in:
parent
ddfa140e41
commit
94ef091902
2 changed files with 136 additions and 135 deletions
|
@ -8,37 +8,37 @@ vim.opt_local.expandtab = true
|
|||
|
||||
local status, jdtls = pcall(require, "jdtls")
|
||||
if not status then
|
||||
return
|
||||
return
|
||||
end
|
||||
|
||||
local function capabilities()
|
||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if status_ok then
|
||||
return cmp_nvim_lsp.default_capabilities()
|
||||
end
|
||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if status_ok then
|
||||
return cmp_nvim_lsp.default_capabilities()
|
||||
end
|
||||
|
||||
local CAPABILITIES = vim.lsp.protocol.make_client_capabilities()
|
||||
CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true
|
||||
CAPABILITIES.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = {
|
||||
"documentation",
|
||||
"detail",
|
||||
"additionalTextEdits",
|
||||
},
|
||||
}
|
||||
local CAPABILITIES = vim.lsp.protocol.make_client_capabilities()
|
||||
CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true
|
||||
CAPABILITIES.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = {
|
||||
"documentation",
|
||||
"detail",
|
||||
"additionalTextEdits",
|
||||
},
|
||||
}
|
||||
|
||||
return CAPABILITIES
|
||||
return CAPABILITIES
|
||||
end
|
||||
|
||||
local function directory_exists(path)
|
||||
local f = io.popen("cd " .. path)
|
||||
local ff = f:read("*all")
|
||||
local f = io.popen("cd " .. path)
|
||||
local ff = f:read("*all")
|
||||
|
||||
if ff:find("ItemNotFoundException") then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
if ff:find("ItemNotFoundException") then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
|
||||
|
@ -49,7 +49,7 @@ local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
|||
local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name
|
||||
if directory_exists(workspace_dir) then
|
||||
else
|
||||
os.execute("mkdir " .. workspace_dir)
|
||||
os.execute("mkdir " .. workspace_dir)
|
||||
end
|
||||
-- get the mason install path
|
||||
local install_path = require("mason-registry").get_package("jdtls"):get_install_path()
|
||||
|
@ -57,85 +57,86 @@ local install_path = require("mason-registry").get_package("jdtls"):get_install_
|
|||
-- get the current OS
|
||||
local os
|
||||
if vim.fn.has("macunix") then
|
||||
os = "mac"
|
||||
os = "mac"
|
||||
elseif vim.fn.has("win32") then
|
||||
os = "win"
|
||||
os = "win"
|
||||
else
|
||||
os = "linux"
|
||||
os = "linux"
|
||||
end
|
||||
|
||||
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"
|
||||
)
|
||||
bundles,
|
||||
vim.split(
|
||||
vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"),
|
||||
"\n"
|
||||
)
|
||||
)
|
||||
|
||||
local config = {
|
||||
cmd = {
|
||||
"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",
|
||||
"-javaagent:" .. install_path .. "/lombok.jar",
|
||||
"-Xms1g",
|
||||
"--add-modules=ALL-SYSTEM",
|
||||
"--add-opens",
|
||||
"java.base/java.util=ALL-UNNAMED",
|
||||
"--add-opens",
|
||||
"java.base/java.lang=ALL-UNNAMED",
|
||||
"-jar",
|
||||
vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"),
|
||||
"-configuration",
|
||||
install_path .. "/config_" .. os,
|
||||
"-data",
|
||||
workspace_dir,
|
||||
},
|
||||
capabilities = capabilities(),
|
||||
root_dir = root_dir,
|
||||
settings = {
|
||||
java = {},
|
||||
},
|
||||
cmd = {
|
||||
"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",
|
||||
"-javaagent:" .. install_path .. "/lombok.jar",
|
||||
"-Xms1g",
|
||||
"--add-modules=ALL-SYSTEM",
|
||||
"--add-opens",
|
||||
"java.base/java.util=ALL-UNNAMED",
|
||||
"--add-opens",
|
||||
"java.base/java.lang=ALL-UNNAMED",
|
||||
"-jar",
|
||||
vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"),
|
||||
"-configuration",
|
||||
install_path .. "/config_" .. os,
|
||||
"-data",
|
||||
workspace_dir,
|
||||
},
|
||||
capabilities = capabilities(),
|
||||
root_dir = root_dir,
|
||||
settings = {
|
||||
java = {},
|
||||
},
|
||||
|
||||
init_options = {
|
||||
bundles = {
|
||||
vim.fn.glob(
|
||||
mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
||||
"\n"
|
||||
),
|
||||
},
|
||||
},
|
||||
init_options = {
|
||||
bundles = bundles,
|
||||
-- bundles = {
|
||||
-- vim.fn.glob(
|
||||
-- mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
||||
-- "\n"
|
||||
-- ),
|
||||
-- },
|
||||
},
|
||||
}
|
||||
|
||||
config["on_attach"] = function(client, bufnr)
|
||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||
|
||||
-- valdation if DAP not installed
|
||||
local dap_status, _ = pcall(require, "nvim-dap")
|
||||
if not dap_status then
|
||||
return
|
||||
end
|
||||
-- valdation if DAP not installed
|
||||
local dap_status, _ = pcall(require, "nvim-dap")
|
||||
if not dap_status then
|
||||
return
|
||||
end
|
||||
|
||||
require("jdtls.dap").setup_dap_main_class_configs()
|
||||
jdtls.setup_dap({ hotcodereplace = "auto" })
|
||||
require("user.lsp.handlers").on_attach(client, bufnr)
|
||||
require("jdtls.dap").setup_dap_main_class_configs()
|
||||
jdtls.setup_dap({ hotcodereplace = "auto" })
|
||||
require("user.lsp.handlers").on_attach(client, bufnr)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||||
pattern = { "*.java" },
|
||||
callback = function()
|
||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||
end,
|
||||
pattern = { "*.java" },
|
||||
callback = function()
|
||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||
end,
|
||||
})
|
||||
|
||||
jdtls.start_or_attach(config)
|
||||
|
||||
vim.cmd(
|
||||
[[command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime(<f-args>)]]
|
||||
[[command! -buffer -nargs=? -complete=custom,v:lua.require'jdtls'._complete_set_runtime JdtSetRuntime lua require('jdtls').set_runtime(<f-args>)]]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue