forked from ayamir/nvimdots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(DAP): improve user experience (ayamir#777)
* fix: make dap for c/cpp/rust/python works. * refactor: use cpptools to debug c/cpp/rust. * refactor: make dap servers configurable. * refactor: move dap servers config to subdir. * refactor: use mason-nvim-dap.nvim to manage dap servers. * perf: add note for each dap server. * fixup! refactor: make debug functionality better * fixup! fixup! refactor: make debug functionality better * fix typo * re-format code * feat: simplify `utils/dap.lua` * fixup! add checks for Windows NT (`codelldb`) * fixup! fixup! remove redundant comment * fixup! fix path expansion * fix: expand current file path to exe prompt. --------- Co-authored-by: Jint-lzxy <[email protected]>
- Loading branch information
1 parent
2053b31
commit 61fde8b
Showing
10 changed files
with
314 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- 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 = "Launch the debugger", | ||
type = "codelldb", | ||
request = "launch", | ||
program = utils.input_exec_path(), | ||
args = utils.input_args(), | ||
cwd = "${workspaceFolder}", | ||
stopOnEntry = false, | ||
}, | ||
} | ||
dap.configurations.cpp = dap.configurations.c | ||
dap.configurations.rust = dap.configurations.c | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go-using-delve-directly | ||
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md | ||
return function() | ||
local dap = require("dap") | ||
local utils = require("modules.utils.dap") | ||
|
||
dap.adapters.go = function(callback) | ||
local stdout = vim.loop.new_pipe(false) | ||
local handle | ||
local pid_or_err | ||
local port = 28695 | ||
local opts = { | ||
stdio = { nil, stdout }, | ||
args = { "dap", "-l", "127.0.0.1:" .. port }, | ||
detached = true, | ||
} | ||
handle, pid_or_err = vim.loop.spawn(vim.fn.exepath("dlv"), opts, function(code) | ||
stdout:close() | ||
handle:close() | ||
if code ~= 0 then | ||
vim.notify( | ||
string.format('"dlv" exited with code: %d, please check your configs for correctness.', code), | ||
vim.log.levels.WARN, | ||
{ title = "[go] DAP Warning!" } | ||
) | ||
end | ||
end) | ||
assert(handle, "Error running dlv: " .. tostring(pid_or_err)) | ||
stdout:read_start(function(err, chunk) | ||
assert(not err, err) | ||
if chunk then | ||
vim.schedule(function() | ||
require("dap.repl").append(chunk) | ||
end) | ||
end | ||
end) | ||
-- Wait for delve to start | ||
vim.defer_fn(function() | ||
callback({ type = "server", host = "127.0.0.1", port = port }) | ||
end, 100) | ||
end | ||
dap.configurations.go = { | ||
{ type = "go", name = "Debug", request = "launch", program = "${file}" }, | ||
{ | ||
type = "go", | ||
name = "Debug with args", | ||
request = "launch", | ||
program = "${file}", | ||
args = utils.input_args(), | ||
}, | ||
{ | ||
type = "go", | ||
name = "Debug test", -- configuration for debugging test files | ||
request = "launch", | ||
mode = "test", | ||
program = "${file}", | ||
}, -- works with go.mod packages and sub packages | ||
{ | ||
type = "go", | ||
name = "Debug test (go.mod)", | ||
request = "launch", | ||
mode = "test", | ||
program = "./${relativeFileDirname}", | ||
}, | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- 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 = "lldb-vscode", | ||
name = "lldb", | ||
} | ||
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 |
Oops, something went wrong.