forked from abzcoding/lvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdap.lua
More file actions
252 lines (237 loc) Β· 6.42 KB
/
dap.lua
File metadata and controls
252 lines (237 loc) Β· 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
local M = {}
M.config = function()
local function sep_os_replacer(str)
local result = str
local path_sep = package.config:sub(1, 1)
result = result:gsub("/", path_sep)
return result
end
local join_path = require("lvim.utils").join_paths
local status_ok, dap = pcall(require, "dap")
if not status_ok then
return
end
dap.configurations.lua = {
{
type = "nlua",
request = "attach",
name = "Neovim attach",
host = function()
local value = vim.fn.input "Host [127.0.0.1]: "
if value ~= "" then
return value
end
return "127.0.0.1"
end,
port = function()
local val = tonumber(vim.fn.input "Port: ")
assert(val, "Please provide a port number")
return val
end,
},
}
dap.adapters.go = function(callback, _)
local stdout = vim.loop.new_pipe(false)
local handle
local pid_or_err
local port = 38697
local opts = {
stdio = { nil, stdout },
args = { "dap", "-l", "127.0.0.1:" .. port },
detached = true,
}
handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code)
stdout:close()
handle:close()
if code ~= 0 then
print("dlv exited with code", code)
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
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
dap.configurations.go = {
{
type = "go",
name = "Debug",
request = "launch",
program = "${file}",
},
{
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}",
},
}
dap.configurations.dart = {
{
type = "dart",
request = "launch",
name = "Launch flutter",
dartSdkPath = sep_os_replacer(join_path(vim.fn.expand "~/", "/flutter/bin/cache/dart-sdk/")),
flutterSdkPath = sep_os_replacer(join_path(vim.fn.expand "~/", "/flutter")),
program = sep_os_replacer "${workspaceFolder}/lib/main.dart",
cwd = "${workspaceFolder}",
},
}
dap.adapters.firefox = {
type = "executable",
command = "node",
args = {
join_path(
vim.fn.expand "~/",
"/.vscode/extensions/firefox-devtools.vscode-firefox-debug-2.9.6/dist/adapter.bundle.js"
),
},
}
local firefoxExecutable = "/usr/bin/firefox"
if vim.fn.has "mac" == 1 then
firefoxExecutable = "/Applications/Firefox.app/Contents/MacOS/firefox"
end
dap.configurations.typescript = {
{
type = "node2",
name = "node attach",
request = "attach",
program = "${file}",
cwd = vim.fn.getcwd(),
sourceMaps = true,
protocol = "inspector",
},
{
type = "chrome",
name = "chrome",
request = "attach",
program = "${file}",
-- cwd = "${workspaceFolder}",
-- protocol = "inspector",
port = 9222,
webRoot = "${workspaceFolder}",
-- sourceMaps = true,
sourceMapPathOverrides = {
-- Sourcemap override for nextjs
["webpack://_N_E/./*"] = "${webRoot}/*",
["webpack:///./*"] = "${webRoot}/*",
},
},
{
name = "Debug with Firefox",
type = "firefox",
request = "launch",
reAttach = true,
sourceMaps = true,
url = "http://localhost:6969",
webRoot = "${workspaceFolder}",
firefoxExecutable = firefoxExecutable,
},
}
dap.configurations.typescriptreact = dap.configurations.typescript
dap.configurations.javascript = dap.configurations.typescript
dap.configurations.javascriptreact = dap.configurations.typescript
dap.adapters.codelldb = function(on_adapter)
local stdout = vim.loop.new_pipe(false)
local stderr = vim.loop.new_pipe(false)
local cmd = vim.fn.expand "~/" .. ".vscode/extensions/vadimcn.vscode-lldb-1.6.10/adapter/codelldb"
local handle, pid_or_err
local opts = {
stdio = { nil, stdout, stderr },
detached = true,
}
handle, pid_or_err = vim.loop.spawn(cmd, opts, function(code)
stdout:close()
stderr:close()
handle:close()
if code ~= 0 then
print("codelldb exited with code", code)
end
end)
assert(handle, "Error running codelldb: " .. tostring(pid_or_err))
stdout:read_start(function(err, chunk)
assert(not err, err)
if chunk then
local port = chunk:match "Listening on port (%d+)"
if port then
vim.schedule(function()
on_adapter {
type = "server",
host = "127.0.0.1",
port = port,
}
end)
else
vim.schedule(function()
require("dap.repl").append(chunk)
end)
end
end
end)
stderr:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require("dap.repl").append(chunk)
end)
end
end)
end
dap.configurations.cpp = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = true,
},
}
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp
if lvim.builtin.metals.active then
dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "Run or Test Target",
metals = {
runType = "runOrTestFile",
},
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = {
runType = "testTarget",
},
},
}
end
lvim.builtin.dap.on_config_done = function(_)
lvim.builtin.which_key.mappings["d"].name = "ο Debug"
end
end
return M