feat: nestjs dap configured
This commit is contained in:
parent
47419e74f8
commit
3afc48617a
@ -1,3 +1,60 @@
|
|||||||
|
-- Function to evaluate the variable or expression under the cursor or selected in visual mode
|
||||||
|
local function dap_evaluate_expression()
|
||||||
|
local dap = require("dap")
|
||||||
|
if not dap.session() then
|
||||||
|
print("No active debug session")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Determine if we're in visual mode and get the expression
|
||||||
|
local expression
|
||||||
|
local mode = vim.fn.mode()
|
||||||
|
if mode == "v" or mode == "V" or mode == "<C-v>" then
|
||||||
|
-- Visual mode: grab the selected text
|
||||||
|
local start_pos = vim.fn.getpos("v")
|
||||||
|
local end_pos = vim.fn.getpos(".")
|
||||||
|
local start_line, start_col = start_pos[2], start_pos[3]
|
||||||
|
local end_line, end_col = end_pos[2], end_pos[3]
|
||||||
|
|
||||||
|
-- Handle multi-line selections or single-line selections
|
||||||
|
if start_line == end_line then
|
||||||
|
local line = vim.fn.getline(start_line)
|
||||||
|
expression = string.sub(line, start_col, end_col)
|
||||||
|
else
|
||||||
|
local lines = vim.fn.getline(start_line, end_line)
|
||||||
|
lines[1] = string.sub(lines[1], start_col)
|
||||||
|
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||||
|
expression = table.concat(lines, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Exit visual mode after grabbing the selection
|
||||||
|
vim.api.nvim_command("normal! <Esc>")
|
||||||
|
else
|
||||||
|
-- Normal mode: grab the word under the cursor
|
||||||
|
expression = vim.fn.expand("<cword>")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ask the debugger to evaluate the expression
|
||||||
|
dap.session():request("evaluate", {
|
||||||
|
expression = expression,
|
||||||
|
context = "repl",
|
||||||
|
}, function(err, response)
|
||||||
|
if err then
|
||||||
|
print("Error evaluating expression: " .. err.message)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if response and response.result then
|
||||||
|
-- Show the result in the command line
|
||||||
|
vim.api.nvim_echo({ { expression .. " = " .. response.result, "Normal" } }, true, {})
|
||||||
|
else
|
||||||
|
print("No result for expression: " .. expression)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Bind it to a key, e.g., <leader>de
|
||||||
|
vim.keymap.set("n", "<leader>de", dap_evaluate_expression, { desc = "Evaluate expression under cursor" })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"mfussenegger/nvim-dap",
|
"mfussenegger/nvim-dap",
|
||||||
recommended = true,
|
recommended = true,
|
||||||
@ -42,6 +99,20 @@ return {
|
|||||||
end
|
end
|
||||||
for _, lang in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact" }) do
|
for _, lang in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact" }) do
|
||||||
dap.configurations[lang] = {
|
dap.configurations[lang] = {
|
||||||
|
{
|
||||||
|
type = "pwa-node",
|
||||||
|
request = "launch",
|
||||||
|
name = "Launch NestJS App",
|
||||||
|
program = "${workspaceFolder}/src/main.ts",
|
||||||
|
runtimeExecutable = "node",
|
||||||
|
runtimeArgs = { "-r", "ts-node/register" },
|
||||||
|
envFile = "${workspaceFolder}/.env",
|
||||||
|
trace = true,
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
sourceMaps = true,
|
||||||
|
protocol = "inspector",
|
||||||
|
console = "integratedTerminal",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type = "pwa-node",
|
type = "pwa-node",
|
||||||
request = "launch",
|
request = "launch",
|
||||||
@ -88,6 +159,23 @@ return {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dap.adapters.cortex = {
|
||||||
|
type = "executable",
|
||||||
|
command = "arm-none-eabi-gdb",
|
||||||
|
args = { "-x", "${workspaceFolder}/debug.gdb" },
|
||||||
|
}
|
||||||
|
|
||||||
|
dap.configurations.c = {
|
||||||
|
{
|
||||||
|
name = "Debug STM32",
|
||||||
|
type = "cortex",
|
||||||
|
request = "launch",
|
||||||
|
program = "${workspaceFolder}/build/main.elf",
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
stopOnEntry = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
-- setup dap config by VsCode launch.json file
|
-- setup dap config by VsCode launch.json file
|
||||||
local vscode = require("dap.ext.vscode")
|
local vscode = require("dap.ext.vscode")
|
||||||
local json = require("plenary.json")
|
local json = require("plenary.json")
|
||||||
@ -110,6 +198,12 @@ return {
|
|||||||
end,
|
end,
|
||||||
desc = "Breakpoint Condition",
|
desc = "Breakpoint Condition",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"<leader>de",
|
||||||
|
dap_evaluate_expression,
|
||||||
|
desc = "Evaluate expression under cursor or selection",
|
||||||
|
mode = { "n", "v" },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"<leader>db",
|
"<leader>db",
|
||||||
function()
|
function()
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
return {
|
||||||
|
"theHamsta/nvim-dap-virtual-text",
|
||||||
|
config = function()
|
||||||
|
require("nvim-dap-virtual-text").setup({
|
||||||
|
enabled = true, -- enable this plugin (the default)
|
||||||
|
enabled_commands = true, -- create commands DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, (DapVirtualTextForceRefresh for refreshing when debug adapter did not notify its termination)
|
||||||
|
highlight_changed_variables = true, -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText
|
||||||
|
highlight_new_as_changed = false, -- highlight new variables in the same way as changed variables (if highlight_changed_variables)
|
||||||
|
show_stop_reason = true, -- show stop reason when stopped for exceptions
|
||||||
|
commented = false, -- prefix virtual text with comment string
|
||||||
|
only_first_definition = true, -- only show virtual text at first definition (if there are multiple)
|
||||||
|
all_references = false, -- show virtual text on all all references of the variable (not only definitions)
|
||||||
|
clear_on_continue = false, -- clear virtual text on "continue" (might cause flickering when stepping)
|
||||||
|
--- A callback that determines how a variable is displayed or whether it should be omitted
|
||||||
|
--- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable
|
||||||
|
--- @param buf number
|
||||||
|
--- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame
|
||||||
|
--- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`)
|
||||||
|
--- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text
|
||||||
|
--- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed
|
||||||
|
display_callback = function(variable, buf, stackframe, node, options)
|
||||||
|
-- by default, strip out new line characters
|
||||||
|
if options.virt_text_pos == "inline" then
|
||||||
|
return " = " .. variable.value:gsub("%s+", " ")
|
||||||
|
else
|
||||||
|
return variable.name .. " = " .. variable.value:gsub("%s+", " ")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
-- position of virtual text, see `:h nvim_buf_set_extmark()`, default tries to inline the virtual text. Use 'eol' to set to end of line
|
||||||
|
virt_text_pos = vim.fn.has("nvim-0.10") == 1 and "inline" or "eol",
|
||||||
|
|
||||||
|
-- experimental features:
|
||||||
|
all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine.
|
||||||
|
virt_lines = false, -- show virtual lines instead of virtual text (will flicker!)
|
||||||
|
virt_text_win_col = nil, -- position the virtual text at a fixed window column (starting from the first text column) ,
|
||||||
|
-- e.g. 80 to position at column 80, see `:h nvim_buf_set_extmark()`
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user