This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugHelper.lua
113 lines (104 loc) · 2.67 KB
/
debugHelper.lua
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
local dap = require('dap')
-- global lua function that when run, presents you choices of which config to run and then asks for arguments.
function _G.dapRunConfigWithArgs()
local dap = require('dap')
local ft = vim.bo.filetype
if ft == "" then
print("Filetype option is required to determine which dap configs are available")
return
end
local configs = dap.configurations[ft]
if configs == nil then
print("Filetype \"" .. ft .. "\" has no dap configs")
return
end
local mConfig = nil
vim.ui.select(
configs,
{
prompt = "Select config to run: ",
format_item = function(config)
return config.name
end
},
function(config)
mConfig = config
end
)
-- redraw to make ui selector disappear
vim.api.nvim_command("redraw")
if mConfig == nil then
return
end
vim.ui.input(
{
prompt = mConfig.name .." - with args: ",
},
function(input)
if input == nil then
return
end
local args = vim.split(input, ' ', true)
mConfig.args = args
dap.run(mConfig)
end
)
end
local function attachToNode()
print("attaching to node process")
dap.run({
type = 'node2',
request = 'attach',
cwd = vim.fn.getcwd(),
sourceMaps = true,
protocol = 'inspector',
skipFiles = {'<node_internals>/**/*.js'},
})
end
local function attachToChrome()
print("attaching to Chrome process")
dap.run({
type = "chrome",
request = "attach",
program = "${file}",
cwd = vim.fn.getcwd(),
sourceMaps = true,
protocol = "inspector",
port = 9222,
webRoot = "${workspaceFolder}"
})
end
local function debugJest(testName, fileName)
print("starting " .. testName .. " with file " .. fileName)
dap.run({
type = 'node2',
request = 'launch',
cwd = vim.fn.getcwd(),
runtimeArgs = {'--inspect-brk', '${workspaceFolder}/node_modules/.bin/jest', '--no-coverage', '-t', string.format("%s", testName), '--', fileName},
sourceMaps = true,
protocol = 'inspector',
skipFiles = {'<node_internals>/**/*.js'},
console = 'integratedTerminal',
port = 9229,
})
end
local function attachToRemote()
print("attaching")
dap.run({
type = 'node2',
request = 'attach',
address = "127.0.0.1",
port = 9229,
localRoot = vim.fn.getcwd(),
remoteRoot = "/home/vcap/app",
sourceMaps = true,
protocol = 'inspector',
skipFiles = {'<node_internals>/**/*.js'},
})
end
return {
debugJest = debugJest,
attachToNode = attachToNode,
attachToChrome = attachToChrome,
attachToRemote = attachToRemote,
}