feat: add nvimdots
This commit is contained in:
47
nvim/lua/modules/configs/tool/dap/clients/codelldb.lua
Normal file
47
nvim/lua/modules/configs/tool/dap/clients/codelldb.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
-- https://github.com/mfussenegger/nvim-dap/wiki/C-C---Rust-(via--codelldb)
|
||||
return function()
|
||||
local dap = require("dap")
|
||||
local utils = require("modules.utils.dap")
|
||||
local is_windows = require("core.global").is_windows
|
||||
|
||||
dap.adapters.codelldb = {
|
||||
type = "server",
|
||||
port = "${port}",
|
||||
executable = {
|
||||
command = vim.fn.exepath("codelldb"), -- Find codelldb on $PATH
|
||||
args = { "--port", "${port}" },
|
||||
detached = is_windows and false or true,
|
||||
},
|
||||
}
|
||||
dap.configurations.c = {
|
||||
{
|
||||
name = "Debug",
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
program = utils.input_exec_path(),
|
||||
cwd = "${workspaceFolder}",
|
||||
stopOnEntry = false,
|
||||
terminal = "integrated",
|
||||
},
|
||||
{
|
||||
name = "Debug (with args)",
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
program = utils.input_exec_path(),
|
||||
args = utils.input_args(),
|
||||
cwd = "${workspaceFolder}",
|
||||
stopOnEntry = false,
|
||||
terminal = "integrated",
|
||||
},
|
||||
{
|
||||
name = "Attach to a running process",
|
||||
type = "codelldb",
|
||||
request = "attach",
|
||||
program = utils.input_exec_path(),
|
||||
stopOnEntry = false,
|
||||
waitFor = true,
|
||||
},
|
||||
}
|
||||
dap.configurations.cpp = dap.configurations.c
|
||||
dap.configurations.rust = dap.configurations.c
|
||||
end
|
||||
100
nvim/lua/modules/configs/tool/dap/clients/delve.lua
Normal file
100
nvim/lua/modules/configs/tool/dap/clients/delve.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go
|
||||
-- https://github.com/golang/vscode-go/blob/master/docs/debugging.md
|
||||
return function()
|
||||
local dap = require("dap")
|
||||
local utils = require("modules.utils.dap")
|
||||
|
||||
if not require("mason-registry").is_installed("go-debug-adapter") then
|
||||
vim.notify(
|
||||
"Automatically installing `go-debug-adapter` for go debugging",
|
||||
vim.log.levels.INFO,
|
||||
{ title = "nvim-dap" }
|
||||
)
|
||||
|
||||
local go_dbg = require("mason-registry").get_package("go-debug-adapter")
|
||||
go_dbg:install():once(
|
||||
"closed",
|
||||
vim.schedule_wrap(function()
|
||||
if go_dbg:is_installed() then
|
||||
vim.notify("Successfully installed `go-debug-adapter`", vim.log.levels.INFO, { title = "nvim-dap" })
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
dap.adapters.go = {
|
||||
type = "executable",
|
||||
command = "node",
|
||||
args = {
|
||||
require("mason-registry").get_package("go-debug-adapter"):get_install_path()
|
||||
.. "/extension/dist/debugAdapter.js",
|
||||
},
|
||||
}
|
||||
dap.configurations.go = {
|
||||
{
|
||||
type = "go",
|
||||
name = "Debug (file)",
|
||||
request = "launch",
|
||||
cwd = "${workspaceFolder}",
|
||||
program = utils.input_file_path(),
|
||||
console = "integratedTerminal",
|
||||
dlvToolPath = vim.fn.exepath("dlv"),
|
||||
showLog = true,
|
||||
showRegisters = true,
|
||||
stopOnEntry = false,
|
||||
},
|
||||
{
|
||||
type = "go",
|
||||
name = "Debug (file with args)",
|
||||
request = "launch",
|
||||
cwd = "${workspaceFolder}",
|
||||
program = utils.input_file_path(),
|
||||
args = utils.input_args(),
|
||||
console = "integratedTerminal",
|
||||
dlvToolPath = vim.fn.exepath("dlv"),
|
||||
showLog = true,
|
||||
showRegisters = true,
|
||||
stopOnEntry = false,
|
||||
},
|
||||
{
|
||||
type = "go",
|
||||
name = "Debug (executable)",
|
||||
request = "launch",
|
||||
cwd = "${workspaceFolder}",
|
||||
program = utils.input_exec_path(),
|
||||
args = utils.input_args(),
|
||||
console = "integratedTerminal",
|
||||
dlvToolPath = vim.fn.exepath("dlv"),
|
||||
mode = "exec",
|
||||
showLog = true,
|
||||
showRegisters = true,
|
||||
stopOnEntry = false,
|
||||
},
|
||||
{
|
||||
type = "go",
|
||||
name = "Debug (test file)",
|
||||
request = "launch",
|
||||
cwd = "${workspaceFolder}",
|
||||
program = utils.input_file_path(),
|
||||
console = "integratedTerminal",
|
||||
dlvToolPath = vim.fn.exepath("dlv"),
|
||||
mode = "test",
|
||||
showLog = true,
|
||||
showRegisters = true,
|
||||
stopOnEntry = false,
|
||||
},
|
||||
{
|
||||
type = "go",
|
||||
name = "Debug (using go.mod)",
|
||||
request = "launch",
|
||||
cwd = "${workspaceFolder}",
|
||||
program = "./${relativeFileDirname}",
|
||||
console = "integratedTerminal",
|
||||
dlvToolPath = vim.fn.exepath("dlv"),
|
||||
mode = "test",
|
||||
showLog = true,
|
||||
showRegisters = true,
|
||||
stopOnEntry = false,
|
||||
},
|
||||
}
|
||||
end
|
||||
36
nvim/lua/modules/configs/tool/dap/clients/lldb.lua
Normal file
36
nvim/lua/modules/configs/tool/dap/clients/lldb.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#ccrust-via-lldb-vscode
|
||||
return function()
|
||||
local dap = require("dap")
|
||||
local utils = require("modules.utils.dap")
|
||||
|
||||
dap.adapters.lldb = {
|
||||
type = "executable",
|
||||
command = vim.fn.exepath("lldb-vscode"), -- Find lldb-vscode on $PATH
|
||||
}
|
||||
dap.configurations.c = {
|
||||
{
|
||||
name = "Launch",
|
||||
type = "lldb",
|
||||
request = "launch",
|
||||
program = utils.input_exec_path(),
|
||||
cwd = "${workspaceFolder}",
|
||||
args = utils.input_args(),
|
||||
env = utils.get_env(),
|
||||
|
||||
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
|
||||
--
|
||||
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
|
||||
--
|
||||
-- Otherwise you might get the following error:
|
||||
--
|
||||
-- Error on launch: Failed to attach to the target process
|
||||
--
|
||||
-- But you should be aware of the implications:
|
||||
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
|
||||
runInTerminal = false,
|
||||
},
|
||||
}
|
||||
|
||||
dap.configurations.cpp = dap.configurations.c
|
||||
dap.configurations.rust = dap.configurations.c
|
||||
end
|
||||
74
nvim/lua/modules/configs/tool/dap/clients/python.lua
Normal file
74
nvim/lua/modules/configs/tool/dap/clients/python.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#python
|
||||
-- https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
|
||||
return function()
|
||||
local dap = require("dap")
|
||||
local utils = require("modules.utils.dap")
|
||||
local is_windows = require("core.global").is_windows
|
||||
local debugpy_root = require("mason-registry").get_package("debugpy"):get_install_path()
|
||||
|
||||
dap.adapters.python = function(callback, config)
|
||||
if config.request == "attach" then
|
||||
local port = (config.connect or config).port
|
||||
local host = (config.connect or config).host or "127.0.0.1"
|
||||
callback({
|
||||
type = "server",
|
||||
port = assert(port, "`connect.port` is required for a python `attach` configuration"),
|
||||
host = host,
|
||||
options = { source_filetype = "python" },
|
||||
})
|
||||
else
|
||||
callback({
|
||||
type = "executable",
|
||||
command = is_windows and debugpy_root .. "/venv/Scripts/pythonw.exe"
|
||||
or debugpy_root .. "/venv/bin/python",
|
||||
args = { "-m", "debugpy.adapter" },
|
||||
options = { source_filetype = "python" },
|
||||
})
|
||||
end
|
||||
end
|
||||
dap.configurations.python = {
|
||||
{
|
||||
-- The first three options are required by nvim-dap
|
||||
type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python`
|
||||
request = "launch",
|
||||
name = "Debug",
|
||||
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
|
||||
console = "integratedTerminal",
|
||||
program = utils.input_file_path(),
|
||||
pythonPath = function()
|
||||
local venv = vim.env.CONDA_PREFIX
|
||||
if venv then
|
||||
return is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python"
|
||||
else
|
||||
return is_windows and "pythonw.exe" or "python3"
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
-- NOTE: This setting is for people using venv
|
||||
type = "python",
|
||||
request = "launch",
|
||||
name = "Debug (using venv)",
|
||||
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
|
||||
console = "integratedTerminal",
|
||||
program = utils.input_file_path(),
|
||||
pythonPath = function()
|
||||
-- Prefer the venv that is defined by the designated environment variable.
|
||||
local cwd, venv = vim.fn.getcwd(), os.getenv("VIRTUAL_ENV")
|
||||
local python = venv and (is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python") or ""
|
||||
if vim.fn.executable(python) == 1 then
|
||||
return python
|
||||
end
|
||||
|
||||
-- Otherwise, fall back to check if there are any local venvs available.
|
||||
venv = vim.fn.isdirectory(cwd .. "/venv") == 1 and cwd .. "/venv" or cwd .. "/.venv"
|
||||
python = is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python"
|
||||
if vim.fn.executable(python) == 1 then
|
||||
return python
|
||||
else
|
||||
return is_windows and "pythonw.exe" or "python3"
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
end
|
||||
21
nvim/lua/modules/configs/tool/dap/dap-keymap.lua
Normal file
21
nvim/lua/modules/configs/tool/dap/dap-keymap.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
local M = {}
|
||||
|
||||
local bind = require("keymap.bind")
|
||||
local map_cmd = bind.map_cmd
|
||||
|
||||
local did_load_debug_mappings = false
|
||||
local debug_keymap = {
|
||||
["nv|K"] = map_cmd("<Cmd>lua require('dapui').eval()<CR>")
|
||||
:with_noremap()
|
||||
:with_nowait()
|
||||
:with_desc("Evaluate expression under cursor"),
|
||||
}
|
||||
|
||||
function M.load_extras()
|
||||
if not did_load_debug_mappings then
|
||||
require("modules.utils.keymap").amend("Debugging", "_debugging", debug_keymap)
|
||||
did_load_debug_mappings = true
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
72
nvim/lua/modules/configs/tool/dap/dapui.lua
Normal file
72
nvim/lua/modules/configs/tool/dap/dapui.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
return function()
|
||||
local icons = {
|
||||
ui = require("modules.utils.icons").get("ui"),
|
||||
dap = require("modules.utils.icons").get("dap"),
|
||||
}
|
||||
|
||||
require("modules.utils").load_plugin("dapui", {
|
||||
force_buffers = true,
|
||||
icons = {
|
||||
expanded = icons.ui.ArrowOpen,
|
||||
collapsed = icons.ui.ArrowClosed,
|
||||
current_frame = icons.ui.Indicator,
|
||||
},
|
||||
mappings = {
|
||||
-- Use a table to apply multiple mappings
|
||||
edit = "e",
|
||||
expand = { "<CR>", "<2-LeftMouse>" },
|
||||
open = "o",
|
||||
remove = "d",
|
||||
repl = "r",
|
||||
toggle = "t",
|
||||
},
|
||||
layouts = {
|
||||
{
|
||||
elements = {
|
||||
-- Provide as ID strings or tables with "id" and "size" keys
|
||||
{
|
||||
id = "scopes",
|
||||
size = 0.3, -- Can be float or integer > 1
|
||||
},
|
||||
{ id = "watches", size = 0.3 },
|
||||
{ id = "stacks", size = 0.3 },
|
||||
{ id = "breakpoints", size = 0.1 },
|
||||
},
|
||||
size = 0.3,
|
||||
position = "right",
|
||||
},
|
||||
{
|
||||
elements = {
|
||||
{ id = "console", size = 0.55 },
|
||||
{ id = "repl", size = 0.45 },
|
||||
},
|
||||
position = "bottom",
|
||||
size = 0.25,
|
||||
},
|
||||
},
|
||||
controls = {
|
||||
enabled = true,
|
||||
-- Display controls in this session
|
||||
element = "repl",
|
||||
icons = {
|
||||
pause = icons.dap.Pause,
|
||||
play = icons.dap.Play,
|
||||
step_into = icons.dap.StepInto,
|
||||
step_over = icons.dap.StepOver,
|
||||
step_out = icons.dap.StepOut,
|
||||
step_back = icons.dap.StepBack,
|
||||
run_last = icons.dap.RunLast,
|
||||
terminate = icons.dap.Terminate,
|
||||
},
|
||||
},
|
||||
floating = {
|
||||
max_height = nil, -- These can be integers or a float between 0 and 1.
|
||||
max_width = nil, -- Floats will be treated as percentage of your screen.
|
||||
border = "single", -- Border style. Can be "single", "double" or "rounded"
|
||||
mappings = {
|
||||
close = { "q", "<Esc>" },
|
||||
},
|
||||
},
|
||||
render = { indent = 1, max_value_lines = 85 },
|
||||
})
|
||||
end
|
||||
84
nvim/lua/modules/configs/tool/dap/init.lua
Normal file
84
nvim/lua/modules/configs/tool/dap/init.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
return function()
|
||||
local dap = require("dap")
|
||||
local dapui = require("dapui")
|
||||
local mason_dap = require("mason-nvim-dap")
|
||||
|
||||
local icons = { dap = require("modules.utils.icons").get("dap") }
|
||||
local colors = require("modules.utils").get_palette()
|
||||
local mappings = require("tool.dap.dap-keymap")
|
||||
|
||||
-- Initialize debug hooks
|
||||
_G._debugging = false
|
||||
local function debug_init_cb()
|
||||
_G._debugging = true
|
||||
mappings.load_extras()
|
||||
dapui.open({ reset = true })
|
||||
end
|
||||
local function debug_terminate_cb()
|
||||
if _debugging then
|
||||
_G._debugging = false
|
||||
dapui.close()
|
||||
end
|
||||
end
|
||||
dap.listeners.after.event_initialized["dapui_config"] = debug_init_cb
|
||||
dap.listeners.before.event_terminated["dapui_config"] = debug_terminate_cb
|
||||
dap.listeners.before.event_exited["dapui_config"] = debug_terminate_cb
|
||||
dap.listeners.before.disconnect["dapui_config"] = debug_terminate_cb
|
||||
|
||||
-- We need to override nvim-dap's default highlight groups, AFTER requiring nvim-dap for catppuccin.
|
||||
vim.api.nvim_set_hl(0, "DapStopped", { fg = colors.green })
|
||||
|
||||
vim.fn.sign_define(
|
||||
"DapBreakpoint",
|
||||
{ text = icons.dap.Breakpoint, texthl = "DapBreakpoint", linehl = "", numhl = "" }
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"DapBreakpointCondition",
|
||||
{ text = icons.dap.BreakpointCondition, texthl = "DapBreakpoint", linehl = "", numhl = "" }
|
||||
)
|
||||
vim.fn.sign_define("DapStopped", { text = icons.dap.Stopped, texthl = "DapStopped", linehl = "", numhl = "" })
|
||||
vim.fn.sign_define(
|
||||
"DapBreakpointRejected",
|
||||
{ text = icons.dap.BreakpointRejected, texthl = "DapBreakpoint", linehl = "", numhl = "" }
|
||||
)
|
||||
vim.fn.sign_define("DapLogPoint", { text = icons.dap.LogPoint, texthl = "DapLogPoint", linehl = "", numhl = "" })
|
||||
|
||||
---A handler to setup all clients defined under `tool/dap/clients/*.lua`
|
||||
---@param config table
|
||||
local function mason_dap_handler(config)
|
||||
local dap_name = config.name
|
||||
local ok, custom_handler = pcall(require, "user.configs.dap-clients." .. dap_name)
|
||||
if not ok then
|
||||
-- Use preset if there is no user definition
|
||||
ok, custom_handler = pcall(require, "tool.dap.clients." .. dap_name)
|
||||
end
|
||||
if not ok then
|
||||
-- Default to use factory config for clients(s) that doesn't include a spec
|
||||
mason_dap.default_setup(config)
|
||||
return
|
||||
elseif type(custom_handler) == "function" then
|
||||
-- Case where the protocol requires its own setup
|
||||
-- Make sure to set
|
||||
-- * dap.adpaters.<dap_name> = { your config }
|
||||
-- * dap.configurations.<lang> = { your config }
|
||||
-- See `codelldb.lua` for a concrete example.
|
||||
custom_handler(config)
|
||||
else
|
||||
vim.notify(
|
||||
string.format(
|
||||
"Failed to setup [%s].\n\nClient definition under `tool/dap/clients` must return\na fun(opts) (got '%s' instead)",
|
||||
config.name,
|
||||
type(custom_handler)
|
||||
),
|
||||
vim.log.levels.ERROR,
|
||||
{ title = "nvim-dap" }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
require("modules.utils").load_plugin("mason-nvim-dap", {
|
||||
ensure_installed = require("core.settings").dap_deps,
|
||||
automatic_installation = true,
|
||||
handlers = { mason_dap_handler },
|
||||
})
|
||||
end
|
||||
Reference in New Issue
Block a user