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")
|
local status, jdtls = pcall(require, "jdtls")
|
||||||
if not status then
|
if not status then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function capabilities()
|
local function capabilities()
|
||||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||||
if status_ok then
|
if status_ok then
|
||||||
return cmp_nvim_lsp.default_capabilities()
|
return cmp_nvim_lsp.default_capabilities()
|
||||||
end
|
end
|
||||||
|
|
||||||
local CAPABILITIES = vim.lsp.protocol.make_client_capabilities()
|
local CAPABILITIES = vim.lsp.protocol.make_client_capabilities()
|
||||||
CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true
|
CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true
|
||||||
CAPABILITIES.textDocument.completion.completionItem.resolveSupport = {
|
CAPABILITIES.textDocument.completion.completionItem.resolveSupport = {
|
||||||
properties = {
|
properties = {
|
||||||
"documentation",
|
"documentation",
|
||||||
"detail",
|
"detail",
|
||||||
"additionalTextEdits",
|
"additionalTextEdits",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAPABILITIES
|
return CAPABILITIES
|
||||||
end
|
end
|
||||||
|
|
||||||
local function directory_exists(path)
|
local function directory_exists(path)
|
||||||
local f = io.popen("cd " .. path)
|
local f = io.popen("cd " .. path)
|
||||||
local ff = f:read("*all")
|
local ff = f:read("*all")
|
||||||
|
|
||||||
if ff:find("ItemNotFoundException") then
|
if ff:find("ItemNotFoundException") then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }
|
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
|
local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name
|
||||||
if directory_exists(workspace_dir) then
|
if directory_exists(workspace_dir) then
|
||||||
else
|
else
|
||||||
os.execute("mkdir " .. workspace_dir)
|
os.execute("mkdir " .. workspace_dir)
|
||||||
end
|
end
|
||||||
-- get the mason install path
|
-- get the mason install path
|
||||||
local install_path = require("mason-registry").get_package("jdtls"):get_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
|
-- get the current OS
|
||||||
local os
|
local os
|
||||||
if vim.fn.has("macunix") then
|
if vim.fn.has("macunix") then
|
||||||
os = "mac"
|
os = "mac"
|
||||||
elseif vim.fn.has("win32") then
|
elseif vim.fn.has("win32") then
|
||||||
os = "win"
|
os = "win"
|
||||||
else
|
else
|
||||||
os = "linux"
|
os = "linux"
|
||||||
end
|
end
|
||||||
|
|
||||||
local bundles = {}
|
local bundles = {}
|
||||||
local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/")
|
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-test/extension/server/*.jar"), "\n"))
|
||||||
vim.list_extend(
|
vim.list_extend(
|
||||||
bundles,
|
bundles,
|
||||||
vim.split(
|
vim.split(
|
||||||
vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"),
|
vim.fn.glob(mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar"),
|
||||||
"\n"
|
"\n"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
cmd = {
|
cmd = {
|
||||||
"java",
|
"java",
|
||||||
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
||||||
"-Dosgi.bundles.defaultStartLevel=4",
|
"-Dosgi.bundles.defaultStartLevel=4",
|
||||||
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
||||||
"-Dlog.protocol=true",
|
"-Dlog.protocol=true",
|
||||||
"-Dlog.level=ALL",
|
"-Dlog.level=ALL",
|
||||||
"-javaagent:" .. install_path .. "/lombok.jar",
|
"-javaagent:" .. install_path .. "/lombok.jar",
|
||||||
"-Xms1g",
|
"-Xms1g",
|
||||||
"--add-modules=ALL-SYSTEM",
|
"--add-modules=ALL-SYSTEM",
|
||||||
"--add-opens",
|
"--add-opens",
|
||||||
"java.base/java.util=ALL-UNNAMED",
|
"java.base/java.util=ALL-UNNAMED",
|
||||||
"--add-opens",
|
"--add-opens",
|
||||||
"java.base/java.lang=ALL-UNNAMED",
|
"java.base/java.lang=ALL-UNNAMED",
|
||||||
"-jar",
|
"-jar",
|
||||||
vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"),
|
vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"),
|
||||||
"-configuration",
|
"-configuration",
|
||||||
install_path .. "/config_" .. os,
|
install_path .. "/config_" .. os,
|
||||||
"-data",
|
"-data",
|
||||||
workspace_dir,
|
workspace_dir,
|
||||||
},
|
},
|
||||||
capabilities = capabilities(),
|
capabilities = capabilities(),
|
||||||
root_dir = root_dir,
|
root_dir = root_dir,
|
||||||
settings = {
|
settings = {
|
||||||
java = {},
|
java = {},
|
||||||
},
|
},
|
||||||
|
|
||||||
init_options = {
|
init_options = {
|
||||||
bundles = {
|
bundles = bundles,
|
||||||
vim.fn.glob(
|
-- bundles = {
|
||||||
mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
-- vim.fn.glob(
|
||||||
"\n"
|
-- mason_path .. "packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
||||||
),
|
-- "\n"
|
||||||
},
|
-- ),
|
||||||
},
|
-- },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
config["on_attach"] = function(client, bufnr)
|
config["on_attach"] = function(client, bufnr)
|
||||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||||
|
|
||||||
-- valdation if DAP not installed
|
-- valdation if DAP not installed
|
||||||
local dap_status, _ = pcall(require, "nvim-dap")
|
local dap_status, _ = pcall(require, "nvim-dap")
|
||||||
if not dap_status then
|
if not dap_status then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
require("jdtls.dap").setup_dap_main_class_configs()
|
require("jdtls.dap").setup_dap_main_class_configs()
|
||||||
jdtls.setup_dap({ hotcodereplace = "auto" })
|
jdtls.setup_dap({ hotcodereplace = "auto" })
|
||||||
require("user.lsp.handlers").on_attach(client, bufnr)
|
require("user.lsp.handlers").on_attach(client, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||||||
pattern = { "*.java" },
|
pattern = { "*.java" },
|
||||||
callback = function()
|
callback = function()
|
||||||
local _, _ = pcall(vim.lsp.codelens.refresh)
|
local _, _ = pcall(vim.lsp.codelens.refresh)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
jdtls.start_or_attach(config)
|
jdtls.start_or_attach(config)
|
||||||
|
|
||||||
vim.cmd(
|
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>)]]
|
||||||
)
|
)
|
||||||
|
|
|
@ -46,62 +46,62 @@ if pcode.active_java_config.active then
|
||||||
{ "<Leader>TS", function() require("neotest").run.stop() end, desc = "Stop" },
|
{ "<Leader>TS", function() require("neotest").run.stop() end, desc = "Stop" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
-- {
|
||||||
"mfussenegger/nvim-dap",
|
-- "mfussenegger/nvim-dap",
|
||||||
event = "BufReadPre",
|
-- event = "BufReadPre",
|
||||||
dependencies = {
|
-- dependencies = {
|
||||||
"rcarriga/nvim-dap-ui",
|
-- "rcarriga/nvim-dap-ui",
|
||||||
"theHamsta/nvim-dap-virtual-text",
|
-- "theHamsta/nvim-dap-virtual-text",
|
||||||
"nvim-neotest/nvim-nio",
|
-- "nvim-neotest/nvim-nio",
|
||||||
"williamboman/mason.nvim",
|
-- "williamboman/mason.nvim",
|
||||||
"jay-babu/mason-nvim-dap.nvim",
|
-- "jay-babu/mason-nvim-dap.nvim",
|
||||||
},
|
-- },
|
||||||
config = function()
|
-- config = function()
|
||||||
require("user.dapui")
|
-- require("user.dapui")
|
||||||
-- local dap = require("dap")
|
-- local dap = require("dap")
|
||||||
-- local util = require("jdtls.util")
|
-- local util = require("jdtls.util")
|
||||||
-- dap.adapters.java = function(callback)
|
-- dap.adapters.java = function(callback)
|
||||||
-- util.execute_command({ command = "vscode.java.startDebugSession" }, function(err0, port)
|
-- util.execute_command({ command = "vscode.java.startDebugSession" }, function(err0, port)
|
||||||
-- if err0 ~= nil then
|
-- if err0 ~= nil then
|
||||||
-- return
|
-- return
|
||||||
-- end
|
-- end
|
||||||
-- callback({ type = "server", host = "127.0.0.1", port = port })
|
-- callback({ type = "server", host = "127.0.0.1", port = port })
|
||||||
-- end)
|
-- end)
|
||||||
-- end
|
-- end
|
||||||
-- dap.configurations.java = {
|
-- dap.configurations.java = {
|
||||||
-- {
|
-- {
|
||||||
-- type = "java",
|
-- type = "java",
|
||||||
-- request = "launch",
|
-- request = "launch",
|
||||||
-- name = "Debug Java",
|
-- name = "Debug Java",
|
||||||
-- program = "${file}",
|
-- program = "${file}",
|
||||||
-- args = {},
|
-- args = {},
|
||||||
-- cwd = vim.fn.getcwd(),
|
-- cwd = vim.fn.getcwd(),
|
||||||
-- stopOnEntry = false,
|
-- stopOnEntry = false,
|
||||||
-- console = "integratedTerminal",
|
-- console = "integratedTerminal",
|
||||||
-- internalConsoleOptions = "neverOpen",
|
-- internalConsoleOptions = "neverOpen",
|
||||||
-- sourceMaps = true,
|
-- sourceMaps = true,
|
||||||
-- outDir = "${workspaceFolder}/out",
|
-- outDir = "${workspaceFolder}/out",
|
||||||
-- },
|
-- },
|
||||||
-- }
|
-- }
|
||||||
end,
|
-- end,
|
||||||
keys = {
|
-- keys = {
|
||||||
{ "<leader>d", "", desc = " Debug" },
|
-- { "<leader>d", "", desc = " Debug" },
|
||||||
{ "<leader>dt", "<cmd>lua require'dap'.toggle_breakpoint()<cr>", desc = "Toggle Breakpoint" },
|
-- { "<leader>dt", "<cmd>lua require'dap'.toggle_breakpoint()<cr>", desc = "Toggle Breakpoint" },
|
||||||
{ "<leader>db", "<cmd>lua require'dap'.step_back()<cr>", desc = "Step Back" },
|
-- { "<leader>db", "<cmd>lua require'dap'.step_back()<cr>", desc = "Step Back" },
|
||||||
{ "<leader>dc", "<cmd>lua require'dap'.continue()<cr>", desc = "Continue" },
|
-- { "<leader>dc", "<cmd>lua require'dap'.continue()<cr>", desc = "Continue" },
|
||||||
{ "<leader>dC", "<cmd>lua require'dap'.run_to_cursor()<cr>", desc = "Run To Cursor" },
|
-- { "<leader>dC", "<cmd>lua require'dap'.run_to_cursor()<cr>", desc = "Run To Cursor" },
|
||||||
{ "<leader>dd", "<cmd>lua require'dap'.disconnect()<cr>", desc = "Disconnect" },
|
-- { "<leader>dd", "<cmd>lua require'dap'.disconnect()<cr>", desc = "Disconnect" },
|
||||||
{ "<leader>dg", "<cmd>lua require'dap'.session()<cr>", desc = "Get Session" },
|
-- { "<leader>dg", "<cmd>lua require'dap'.session()<cr>", desc = "Get Session" },
|
||||||
{ "<leader>di", "<cmd>lua require'dap'.step_into()<cr>", desc = "Step Into" },
|
-- { "<leader>di", "<cmd>lua require'dap'.step_into()<cr>", desc = "Step Into" },
|
||||||
{ "<leader>do", "<cmd>lua require'dap'.step_over()<cr>", desc = "Step Over" },
|
-- { "<leader>do", "<cmd>lua require'dap'.step_over()<cr>", desc = "Step Over" },
|
||||||
{ "<leader>du", "<cmd>lua require'dap'.step_out()<cr>", desc = "Step Out" },
|
-- { "<leader>du", "<cmd>lua require'dap'.step_out()<cr>", desc = "Step Out" },
|
||||||
{ "<leader>dp", "<cmd>lua require'dap'.pause()<cr>", desc = "Pause" },
|
-- { "<leader>dp", "<cmd>lua require'dap'.pause()<cr>", desc = "Pause" },
|
||||||
{ "<leader>dr", "<cmd>lua require'dap'.repl.toggle()<cr>", desc = "Toggle Repl" },
|
-- { "<leader>dr", "<cmd>lua require'dap'.repl.toggle()<cr>", desc = "Toggle Repl" },
|
||||||
{ "<leader>ds", "<cmd>lua require'dap'.continue()<cr>", desc = "Start" },
|
-- { "<leader>ds", "<cmd>lua require'dap'.continue()<cr>", desc = "Start" },
|
||||||
{ "<leader>dq", "<cmd>lua require'dap'.close()<cr>", desc = "Quit" },
|
-- { "<leader>dq", "<cmd>lua require'dap'.close()<cr>", desc = "Quit" },
|
||||||
{ "<leader>dU", "<cmd>lua require'dapui'.toggle({reset = true})<cr>", desc = "Toggle UI" },
|
-- { "<leader>dU", "<cmd>lua require'dapui'.toggle({reset = true})<cr>", desc = "Toggle UI" },
|
||||||
},
|
-- },
|
||||||
},
|
-- },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue