audit: comprehensive cleanup — delete 8 files, fix buffer bug, cut bloat
This commit is contained in:
28 files changed
+279
-656
No files matched your search
@@ -24,7 +24,6 @@ function M.register(dap)
|
||||
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
|
||||
end,
|
||||
cwd = "${workspaceFolder}",
|
||||
stopOnEntry = false,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
local netcoredbg = loader.find_executable({ "netcoredbg" })
|
||||
if not netcoredbg then return end
|
||||
|
||||
loader.register(dap, "netcoredbg", {
|
||||
type = "executable",
|
||||
command = netcoredbg,
|
||||
args = { "--interpreter=vscode" },
|
||||
}, {
|
||||
{
|
||||
type = "netcoredbg",
|
||||
request = "launch",
|
||||
name = "Launch .NET",
|
||||
program = function()
|
||||
return vim.fn.input("Path to DLL: ", vim.fn.getcwd() .. "/bin/Debug/", "file")
|
||||
end,
|
||||
},
|
||||
}, { "cs" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -6,30 +6,83 @@ local mason_bin = vim.fn.stdpath("data") .. "/mason/bin/"
|
||||
|
||||
function M.find_executable(names)
|
||||
for _, name in ipairs(names) do
|
||||
-- check PATH
|
||||
if vim.fn.executable(name) == 1 then
|
||||
return name
|
||||
end
|
||||
-- check mason
|
||||
if vim.fn.executable(name) == 1 then return name end
|
||||
local mason_path = mason_bin .. name
|
||||
if vim.fn.executable(mason_path) == 1 then
|
||||
return mason_path
|
||||
end
|
||||
if vim.fn.executable(mason_path) == 1 then return mason_path end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function M.register(dap, name, adapter, configurations, filetypes)
|
||||
-- don't override user-configured adapters
|
||||
if dap.adapters[name] then return end
|
||||
|
||||
dap.adapters[name] = adapter
|
||||
|
||||
for _, ft in ipairs(filetypes) do
|
||||
if not dap.configurations[ft] then
|
||||
dap.configurations[ft] = configurations
|
||||
dap.configurations[ft] = dap.configurations[ft] or configurations
|
||||
end
|
||||
end
|
||||
|
||||
-- simple executable adapters (inlined — no separate files needed)
|
||||
local function register_simple_adapters(dap)
|
||||
local simple = {
|
||||
{ "netcoredbg", { "netcoredbg" }, {
|
||||
type = "executable", args = { "--interpreter=vscode" },
|
||||
}, { {
|
||||
type = "netcoredbg", request = "launch", name = "Launch .NET",
|
||||
program = function() return vim.fn.input("Path to DLL: ", vim.fn.getcwd() .. "/bin/Debug/", "file") end,
|
||||
} }, { "cs" } },
|
||||
|
||||
{ "java", { "java-debug-adapter" }, {
|
||||
type = "executable",
|
||||
}, { {
|
||||
type = "java", request = "launch", name = "Launch class",
|
||||
mainClass = function() return vim.fn.input("Main class: ") end,
|
||||
cwd = "${workspaceFolder}",
|
||||
} }, { "java" } },
|
||||
|
||||
{ "kotlin", { "kotlin-debug-adapter" }, {
|
||||
type = "executable",
|
||||
}, { {
|
||||
type = "kotlin", request = "launch", name = "Launch main",
|
||||
mainClass = function() return vim.fn.input("Main class: ") end,
|
||||
projectRoot = "${workspaceFolder}",
|
||||
} }, { "kotlin" } },
|
||||
|
||||
{ "php", { "php-debug-adapter" }, {
|
||||
type = "executable",
|
||||
}, { {
|
||||
type = "php", request = "launch", name = "Listen for Xdebug", port = 9003,
|
||||
} }, { "php" } },
|
||||
|
||||
{ "rdbg", { "rdbg" }, {
|
||||
type = "server", port = "${port}",
|
||||
executable = { command = nil, args = { "-n", "--open", "--port", "${port}", "-c", "--", "ruby", "${file}" } },
|
||||
}, { {
|
||||
type = "rdbg", request = "launch", name = "Launch file", command = "ruby", script = "${file}",
|
||||
}, {
|
||||
type = "rdbg", request = "attach", name = "Attach", localfsMap = "${workspaceFolder}",
|
||||
} }, { "ruby" } },
|
||||
}
|
||||
|
||||
for _, s in ipairs(simple) do
|
||||
local name, exe_names, adapter_tpl, configurations, filetypes = s[1], s[2], s[3], s[4], s[5]
|
||||
local exe = M.find_executable(exe_names)
|
||||
if exe then
|
||||
local adapter = vim.deepcopy(adapter_tpl)
|
||||
adapter.command = adapter.command or exe
|
||||
if adapter.executable then adapter.executable.command = exe end
|
||||
M.register(dap, name, adapter, configurations, filetypes)
|
||||
end
|
||||
end
|
||||
|
||||
-- lua/neovim (osv) — optional, skip if not installed
|
||||
local ok, osv = pcall(require, "osv")
|
||||
if ok then
|
||||
M.register(dap, "nlua", {
|
||||
type = "server", host = "127.0.0.1",
|
||||
port = function() return osv.launch({ port = 0 }) end,
|
||||
}, { {
|
||||
type = "nlua", request = "attach", name = "Attach to running Neovim",
|
||||
} }, { "lua" })
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
@@ -37,26 +90,21 @@ function M.setup()
|
||||
|
||||
local dap = require("dap")
|
||||
|
||||
-- load built-in adapter modules
|
||||
local adapters = {
|
||||
"python", "go", "c", "javascript", "cs", "java", "kotlin", "php", "ruby", "lua",
|
||||
}
|
||||
|
||||
for _, name in ipairs(adapters) do
|
||||
-- load adapters with non-trivial logic from separate files
|
||||
for _, name in ipairs({ "python", "go", "c", "javascript" }) do
|
||||
local ok, adapter_mod = pcall(require, "tiny-debugger.adapters." .. name)
|
||||
if ok and adapter_mod.register then
|
||||
adapter_mod.register(dap)
|
||||
end
|
||||
end
|
||||
|
||||
-- apply user adapter overrides
|
||||
-- register simple adapters inlined above
|
||||
register_simple_adapters(dap)
|
||||
|
||||
-- apply user adapter overrides (last — wins over everything)
|
||||
for name, adapter_config in pairs(config.opts.adapters) do
|
||||
if adapter_config.adapter then
|
||||
dap.adapters[name] = adapter_config.adapter
|
||||
end
|
||||
if adapter_config.configurations then
|
||||
dap.configurations[name] = adapter_config.configurations
|
||||
end
|
||||
if adapter_config.adapter then dap.adapters[name] = adapter_config.adapter end
|
||||
if adapter_config.configurations then dap.configurations[name] = adapter_config.configurations end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
local java_debug = loader.find_executable({ "java-debug-adapter" })
|
||||
if not java_debug then return end
|
||||
|
||||
loader.register(dap, "java", {
|
||||
type = "executable",
|
||||
command = java_debug,
|
||||
}, {
|
||||
{
|
||||
type = "java",
|
||||
request = "launch",
|
||||
name = "Launch class",
|
||||
mainClass = function()
|
||||
return vim.fn.input("Main class: ")
|
||||
end,
|
||||
cwd = "${workspaceFolder}",
|
||||
},
|
||||
}, { "java" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -8,7 +8,6 @@ function M.register(dap)
|
||||
|
||||
local adapter = {
|
||||
type = "server",
|
||||
host = "localhost",
|
||||
port = "${port}",
|
||||
executable = {
|
||||
command = js_debug,
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
local kotlin_debug = loader.find_executable({ "kotlin-debug-adapter" })
|
||||
if not kotlin_debug then return end
|
||||
|
||||
loader.register(dap, "kotlin", {
|
||||
type = "executable",
|
||||
command = kotlin_debug,
|
||||
}, {
|
||||
{
|
||||
type = "kotlin",
|
||||
request = "launch",
|
||||
name = "Launch main",
|
||||
mainClass = function()
|
||||
return vim.fn.input("Main class: ")
|
||||
end,
|
||||
projectRoot = "${workspaceFolder}",
|
||||
},
|
||||
}, { "kotlin" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,25 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
-- osv (one-small-step-for-vimkind) is optional — skip gracefully if not installed
|
||||
local ok, osv = pcall(require, "osv")
|
||||
if not ok then return end
|
||||
|
||||
loader.register(dap, "nlua", {
|
||||
type = "server",
|
||||
host = "127.0.0.1",
|
||||
port = function()
|
||||
return osv.launch({ port = 0 })
|
||||
end,
|
||||
}, {
|
||||
{
|
||||
type = "nlua",
|
||||
request = "attach",
|
||||
name = "Attach to running Neovim",
|
||||
},
|
||||
}, { "lua" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,22 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
local php_debug = loader.find_executable({ "php-debug-adapter" })
|
||||
if not php_debug then return end
|
||||
|
||||
loader.register(dap, "php", {
|
||||
type = "executable",
|
||||
command = php_debug,
|
||||
}, {
|
||||
{
|
||||
type = "php",
|
||||
request = "launch",
|
||||
name = "Listen for Xdebug",
|
||||
port = 9003,
|
||||
},
|
||||
}, { "php" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,33 +0,0 @@
|
||||
local loader = require("tiny-debugger.adapters.init")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.register(dap)
|
||||
local rdbg = loader.find_executable({ "rdbg" })
|
||||
if not rdbg then return end
|
||||
|
||||
loader.register(dap, "rdbg", {
|
||||
type = "server",
|
||||
port = "${port}",
|
||||
executable = {
|
||||
command = rdbg,
|
||||
args = { "-n", "--open", "--port", "${port}", "-c", "--", "ruby", "${file}" },
|
||||
},
|
||||
}, {
|
||||
{
|
||||
type = "rdbg",
|
||||
request = "launch",
|
||||
name = "Launch file",
|
||||
command = "ruby",
|
||||
script = "${file}",
|
||||
},
|
||||
{
|
||||
type = "rdbg",
|
||||
request = "attach",
|
||||
name = "Attach",
|
||||
localfsMap = "${workspaceFolder}",
|
||||
},
|
||||
}, { "ruby" })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -12,37 +12,32 @@ function M.setup()
|
||||
load_breakpoints_event = { "BufReadPost" },
|
||||
})
|
||||
|
||||
-- sign highlights
|
||||
vim.api.nvim_set_hl(0, "DapBreakpoint", { fg = "#e06c75" })
|
||||
vim.api.nvim_set_hl(0, "DapBreakpointCondition", { fg = "#e5c07b" })
|
||||
vim.api.nvim_set_hl(0, "DapBreakpointRejected", { fg = "#5c6370" })
|
||||
vim.api.nvim_set_hl(0, "DapStopped", { fg = "#98c379" })
|
||||
vim.api.nvim_set_hl(0, "DapStoppedLine", { bg = "#2e3b2e" })
|
||||
vim.api.nvim_set_hl(0, "DapLogPoint", { fg = "#61afef" })
|
||||
-- sign highlights (default = true so colorschemes can override)
|
||||
vim.api.nvim_set_hl(0, "DapBreakpoint", { default = true, fg = "#e06c75" })
|
||||
vim.api.nvim_set_hl(0, "DapBreakpointCondition", { default = true, fg = "#e5c07b" })
|
||||
vim.api.nvim_set_hl(0, "DapBreakpointRejected", { default = true, fg = "#5c6370" })
|
||||
vim.api.nvim_set_hl(0, "DapStopped", { default = true, fg = "#98c379" })
|
||||
vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, bg = "#2e3b2e" })
|
||||
vim.api.nvim_set_hl(0, "DapLogPoint", { default = true, fg = "#61afef" })
|
||||
|
||||
-- gutter signs
|
||||
vim.fn.sign_define("DapBreakpoint", { text = "🔴", texthl = "DapBreakpoint" })
|
||||
vim.fn.sign_define("DapBreakpointCondition", { text = "🟡", texthl = "DapBreakpointCondition" })
|
||||
vim.fn.sign_define("DapBreakpointRejected", { text = "⭕", texthl = "DapBreakpointRejected" })
|
||||
vim.fn.sign_define("DapStopped", { text = "▶️", texthl = "DapStopped", linehl = "DapStoppedLine" })
|
||||
vim.fn.sign_define("DapLogPoint", { text = "📝", texthl = "DapLogPoint" })
|
||||
|
||||
-- global mappings — these work outside debug mode
|
||||
-- global mappings (work outside debug mode)
|
||||
local keys = config.opts.keys
|
||||
if keys.breakpoint then
|
||||
vim.keymap.set("n", keys.breakpoint, function()
|
||||
require("persistent-breakpoints.api").toggle_breakpoint()
|
||||
end, { silent = true, desc = "tiny-debugger: toggle breakpoint" })
|
||||
end
|
||||
if keys.cond_breakpoint then
|
||||
vim.keymap.set("n", keys.cond_breakpoint, function()
|
||||
require("persistent-breakpoints.api").set_conditional_breakpoint()
|
||||
end, { silent = true, desc = "tiny-debugger: conditional breakpoint" })
|
||||
end
|
||||
if keys.clear_breakpoints then
|
||||
vim.keymap.set("n", keys.clear_breakpoints, function()
|
||||
require("persistent-breakpoints.api").clear_all_breakpoints()
|
||||
end, { silent = true, desc = "tiny-debugger: clear all breakpoints" })
|
||||
local pb = require("persistent-breakpoints.api")
|
||||
local bindings = {
|
||||
{ keys.breakpoint, pb.toggle_breakpoint, "toggle breakpoint" },
|
||||
{ keys.cond_breakpoint, pb.set_conditional_breakpoint, "conditional breakpoint" },
|
||||
{ keys.clear_breakpoints, pb.clear_all_breakpoints, "clear all breakpoints" },
|
||||
}
|
||||
for _, b in ipairs(bindings) do
|
||||
if b[1] then
|
||||
vim.keymap.set("n", b[1], b[2], { silent = true, desc = "tiny-debugger: " .. b[3] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -54,16 +54,13 @@ M.defaults = {
|
||||
adapters = {},
|
||||
}
|
||||
|
||||
M.opts = vim.deepcopy(M.defaults)
|
||||
M.opts = M.defaults
|
||||
|
||||
function M.merge(user_opts)
|
||||
M.opts = vim.tbl_deep_extend("force", vim.deepcopy(M.defaults), user_opts or {})
|
||||
-- preserve false values for disabled keys (tbl_deep_extend drops them)
|
||||
if user_opts and user_opts.keys then
|
||||
for k, v in pairs(user_opts.keys) do
|
||||
if v == false then
|
||||
M.opts.keys[k] = false
|
||||
end
|
||||
if v == false then M.opts.keys[k] = false end
|
||||
end
|
||||
end
|
||||
return M.opts
|
||||
|
||||
+29
-50
@@ -5,50 +5,37 @@ local M = {}
|
||||
local win_id = nil
|
||||
local buf_id = nil
|
||||
|
||||
local key_labels = {
|
||||
continue = "Continue",
|
||||
step_over = "Step over",
|
||||
step_into = "Step into",
|
||||
step_out = "Step out",
|
||||
run_to_cursor = "Run to cursor",
|
||||
breakpoint = "Toggle breakpoint",
|
||||
cond_breakpoint = "Conditional breakpoint",
|
||||
clear_breakpoints = "Clear all breakpoints",
|
||||
watch = "Watch expression",
|
||||
hover = "Hover / inspect",
|
||||
eval = "Eval in REPL",
|
||||
terminate = "Quit debugging",
|
||||
restart = "Restart session",
|
||||
help = "Show this help",
|
||||
local key_info = {
|
||||
{ "continue", "Continue" },
|
||||
{ "step_over", "Step over" },
|
||||
{ "step_into", "Step into" },
|
||||
{ "step_out", "Step out" },
|
||||
{ "run_to_cursor", "Run to cursor" },
|
||||
{ "breakpoint", "Toggle breakpoint" },
|
||||
{ "cond_breakpoint", "Conditional breakpoint" },
|
||||
{ "clear_breakpoints", "Clear all breakpoints" },
|
||||
{ "watch", "Watch expression" },
|
||||
{ "hover", "Hover / inspect" },
|
||||
{ "eval", "Eval in REPL" },
|
||||
{ "terminate", "Quit debugging" },
|
||||
{ "restart", "Restart session" },
|
||||
{ "help", "Show this help" },
|
||||
}
|
||||
|
||||
-- ordered list of key names for consistent display
|
||||
local key_order = {
|
||||
"continue", "step_over", "step_into", "step_out", "run_to_cursor",
|
||||
"breakpoint", "cond_breakpoint", "clear_breakpoints", "watch", "hover", "eval",
|
||||
"terminate", "restart", "help",
|
||||
}
|
||||
|
||||
local function build_lines()
|
||||
local function build_content()
|
||||
local lines = { " tiny-debugger keybindings", "" }
|
||||
local width = #lines[1]
|
||||
local keys = config.opts.keys
|
||||
for _, name in ipairs(key_order) do
|
||||
local key = keys[name]
|
||||
for _, pair in ipairs(key_info) do
|
||||
local key = keys[pair[1]]
|
||||
if key then
|
||||
local label = key_labels[name] or name
|
||||
table.insert(lines, string.format(" %s %s", key, label))
|
||||
local line = string.format(" %s %s", key, pair[2])
|
||||
lines[#lines + 1] = line
|
||||
if #line > width then width = #line end
|
||||
end
|
||||
end
|
||||
table.insert(lines, "")
|
||||
return lines
|
||||
end
|
||||
|
||||
local function calc_width(lines)
|
||||
local max = 0
|
||||
for _, line in ipairs(lines) do
|
||||
max = math.max(max, #line)
|
||||
end
|
||||
return max + 2
|
||||
lines[#lines + 1] = ""
|
||||
return lines, width + 2
|
||||
end
|
||||
|
||||
function M.close()
|
||||
@@ -65,37 +52,29 @@ end
|
||||
function M.open()
|
||||
M.close()
|
||||
|
||||
local lines = build_lines()
|
||||
local width = calc_width(lines)
|
||||
local height = #lines
|
||||
local lines, width = build_content()
|
||||
|
||||
buf_id = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf_id, 0, -1, false, lines)
|
||||
vim.bo[buf_id].modifiable = false
|
||||
vim.bo[buf_id].bufhidden = "wipe"
|
||||
|
||||
local editor_width = vim.o.columns
|
||||
local editor_height = vim.o.lines
|
||||
|
||||
win_id = vim.api.nvim_open_win(buf_id, false, {
|
||||
relative = "editor",
|
||||
anchor = "SE",
|
||||
row = editor_height - 2,
|
||||
col = editor_width,
|
||||
row = vim.o.lines - 2,
|
||||
col = vim.o.columns,
|
||||
width = width,
|
||||
height = height,
|
||||
height = #lines,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
focusable = false,
|
||||
noautocmd = true,
|
||||
})
|
||||
|
||||
-- auto-close on next keypress
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved", "InsertEnter", "CmdlineEnter" }, {
|
||||
once = true,
|
||||
callback = function()
|
||||
M.close()
|
||||
end,
|
||||
callback = function() M.close() end,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
local config = require("tiny-debugger.config")
|
||||
local mode = require("tiny-debugger.mode")
|
||||
local breakpoints = require("tiny-debugger.breakpoints")
|
||||
local adapters = require("tiny-debugger.adapters")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.setup(opts)
|
||||
config.merge(opts)
|
||||
breakpoints.setup()
|
||||
adapters.setup()
|
||||
require("tiny-debugger.breakpoints").setup()
|
||||
require("tiny-debugger.adapters").setup()
|
||||
end
|
||||
|
||||
function M.toggle()
|
||||
|
||||
+59
-53
@@ -1,16 +1,40 @@
|
||||
local config = require("tiny-debugger.config")
|
||||
local help = require("tiny-debugger.help")
|
||||
local ui = require("tiny-debugger.ui")
|
||||
local virtual_text = require("tiny-debugger.virtual_text")
|
||||
|
||||
local M = {}
|
||||
|
||||
local active = false
|
||||
local active_buf = nil
|
||||
local stashed_maps = {}
|
||||
|
||||
-- one-time dap-ui and virtual-text initialization
|
||||
local dapui_initialized = false
|
||||
local vt_initialized = false
|
||||
|
||||
local function ensure_dapui()
|
||||
if dapui_initialized then return end
|
||||
dapui_initialized = true
|
||||
require("dapui").setup(config.opts.dapui)
|
||||
|
||||
local dap = require("dap")
|
||||
dap.listeners.after.event_terminated["tiny-debugger"] = function()
|
||||
if active then M.exit() end
|
||||
end
|
||||
dap.listeners.after.event_exited["tiny-debugger"] = function()
|
||||
if active then M.exit() end
|
||||
end
|
||||
end
|
||||
|
||||
local function ensure_vt()
|
||||
if vt_initialized then return end
|
||||
vt_initialized = true
|
||||
require("nvim-dap-virtual-text").setup(config.opts.virtual_text)
|
||||
end
|
||||
|
||||
-- keymap stash/restore
|
||||
|
||||
local function stash_mapping(buf, lhs)
|
||||
local maps = vim.api.nvim_buf_get_keymap(buf, "n")
|
||||
for _, map in ipairs(maps) do
|
||||
for _, map in ipairs(vim.api.nvim_buf_get_keymap(buf, "n")) do
|
||||
if map.lhs == lhs then
|
||||
stashed_maps[lhs] = map
|
||||
return
|
||||
@@ -37,35 +61,24 @@ local function restore_mapping(buf, lhs)
|
||||
end
|
||||
end
|
||||
|
||||
-- actions table: key name → function
|
||||
-- populated by other modules via M.register_action
|
||||
-- actions (set up once)
|
||||
|
||||
local actions = {}
|
||||
local visual_actions = { watch = true, hover = true }
|
||||
|
||||
function M.register_action(name, fn)
|
||||
actions[name] = fn
|
||||
end
|
||||
|
||||
-- default actions that map directly to dap calls
|
||||
local function setup_default_actions()
|
||||
local function setup_actions()
|
||||
if next(actions) then return end
|
||||
local dap = require("dap")
|
||||
actions.continue = function() dap.continue() end
|
||||
actions.step_over = function() dap.step_over() end
|
||||
actions.step_into = function() dap.step_into() end
|
||||
actions.step_out = function() dap.step_out() end
|
||||
actions.run_to_cursor = function() dap.run_to_cursor() end
|
||||
actions.terminate = function()
|
||||
dap.terminate()
|
||||
M.exit()
|
||||
end
|
||||
actions.terminate = function() dap.terminate(); M.exit() end
|
||||
actions.restart = function() dap.restart() end
|
||||
actions.help = function()
|
||||
if help.is_open() then
|
||||
help.close()
|
||||
else
|
||||
help.open()
|
||||
end
|
||||
if help.is_open() then help.close() else help.open() end
|
||||
end
|
||||
|
||||
actions.watch = function()
|
||||
local expr
|
||||
if vim.fn.mode() == "v" or vim.fn.mode() == "V" then
|
||||
@@ -78,18 +91,11 @@ local function setup_default_actions()
|
||||
require("dapui").elements.watches.add(expr)
|
||||
end
|
||||
end
|
||||
|
||||
actions.hover = function()
|
||||
require("dapui").eval()
|
||||
end
|
||||
|
||||
actions.eval = function()
|
||||
require("dapui").float_element("repl")
|
||||
end
|
||||
actions.hover = function() require("dapui").eval() end
|
||||
actions.eval = function() require("dapui").float_element("repl") end
|
||||
end
|
||||
|
||||
-- actions that also get visual mode mappings
|
||||
local visual_actions = { watch = true, hover = true }
|
||||
-- keymap lifecycle
|
||||
|
||||
local function set_keymaps(buf)
|
||||
local keys = config.opts.keys
|
||||
@@ -118,6 +124,8 @@ local function clear_keymaps(buf)
|
||||
stashed_maps = {}
|
||||
end
|
||||
|
||||
-- cursor highlight
|
||||
|
||||
local saved_cursor_hl = nil
|
||||
|
||||
local function set_cursor_highlight()
|
||||
@@ -126,25 +134,26 @@ local function set_cursor_highlight()
|
||||
end
|
||||
|
||||
local function restore_cursor_highlight()
|
||||
if saved_cursor_hl then
|
||||
vim.api.nvim_set_hl(0, "Cursor", saved_cursor_hl)
|
||||
saved_cursor_hl = nil
|
||||
else
|
||||
vim.api.nvim_set_hl(0, "Cursor", {})
|
||||
end
|
||||
vim.api.nvim_set_hl(0, "Cursor", saved_cursor_hl or {})
|
||||
saved_cursor_hl = nil
|
||||
end
|
||||
|
||||
-- public API
|
||||
|
||||
function M.enter()
|
||||
if active then return end
|
||||
active = true
|
||||
setup_actions()
|
||||
|
||||
setup_default_actions()
|
||||
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
set_keymaps(buf)
|
||||
active_buf = vim.api.nvim_get_current_buf()
|
||||
set_keymaps(active_buf)
|
||||
set_cursor_highlight()
|
||||
ui.open()
|
||||
virtual_text.enable()
|
||||
|
||||
ensure_dapui()
|
||||
require("dapui").open()
|
||||
|
||||
ensure_vt()
|
||||
require("nvim-dap-virtual-text").enable()
|
||||
|
||||
if config.opts.help_on_enter then
|
||||
help.open()
|
||||
@@ -155,20 +164,17 @@ function M.exit()
|
||||
if not active then return end
|
||||
active = false
|
||||
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
clear_keymaps(buf)
|
||||
clear_keymaps(active_buf or vim.api.nvim_get_current_buf())
|
||||
active_buf = nil
|
||||
restore_cursor_highlight()
|
||||
help.close()
|
||||
ui.close()
|
||||
virtual_text.disable()
|
||||
|
||||
if dapui_initialized then require("dapui").close() end
|
||||
if vt_initialized then require("nvim-dap-virtual-text").disable() end
|
||||
end
|
||||
|
||||
function M.toggle()
|
||||
if active then
|
||||
M.exit()
|
||||
else
|
||||
M.enter()
|
||||
end
|
||||
if active then M.exit() else M.enter() end
|
||||
end
|
||||
|
||||
function M.is_active()
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
local config = require("tiny-debugger.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
local initialized = false
|
||||
|
||||
local function ensure_setup()
|
||||
if initialized then return end
|
||||
initialized = true
|
||||
|
||||
local dapui = require("dapui")
|
||||
dapui.setup(config.opts.dapui)
|
||||
|
||||
-- auto-exit debug mode when session ends
|
||||
local dap = require("dap")
|
||||
local mode = require("tiny-debugger.mode")
|
||||
|
||||
dap.listeners.after.event_terminated["tiny-debugger"] = function()
|
||||
if mode.is_active() then
|
||||
mode.exit()
|
||||
end
|
||||
end
|
||||
|
||||
dap.listeners.after.event_exited["tiny-debugger"] = function()
|
||||
if mode.is_active() then
|
||||
mode.exit()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.open()
|
||||
ensure_setup()
|
||||
require("dapui").open()
|
||||
end
|
||||
|
||||
function M.close()
|
||||
if initialized then
|
||||
require("dapui").close()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,24 +0,0 @@
|
||||
local config = require("tiny-debugger.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
local initialized = false
|
||||
|
||||
function M.setup()
|
||||
if initialized then return end
|
||||
initialized = true
|
||||
require("nvim-dap-virtual-text").setup(config.opts.virtual_text)
|
||||
end
|
||||
|
||||
function M.enable()
|
||||
M.setup()
|
||||
require("nvim-dap-virtual-text").enable()
|
||||
end
|
||||
|
||||
function M.disable()
|
||||
if initialized then
|
||||
require("nvim-dap-virtual-text").disable()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user