-16
README.md
-16
README.md
···
25
25
dependencies = {
26
26
"nvim-lua/plenary.nvim",
27
27
"nvim-treesitter/nvim-treesitter",
28
-
"mfussenegger/nvim-dap", -- (optional) only if you use `gopher.dap`
29
28
},
30
29
-- (optional) will update plugin's deps on every update
31
30
build = function()
···
216
215
```
217
216
</details>
218
217
219
-
<details>
220
-
<summary>
221
-
<b>Setup <a href="https://github.com/mfussenegger/nvim-dap">nvim-dap</a> for go in one line</b>
222
-
</summary>
223
-
224
-
THIS FEATURE WILL BE REMOVED IN `0.1.6`
225
-
226
-
note [nvim-dap](https://github.com/mfussenegger/nvim-dap) has to be installed
227
-
228
-
```lua
229
-
require("gopher.dap").setup()
230
-
```
231
-
</details>
232
-
233
218
## Contributing
234
219
235
220
PRs are always welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md)
···
237
222
## Thanks
238
223
239
224
- [go.nvim](https://github.com/ray-x/go.nvim)
240
-
- [nvim-dap-go](https://github.com/leoluz/nvim-dap-go)
241
225
- [iferr](https://github.com/koron/iferr)
+1
-10
doc/gopher.nvim.txt
+1
-10
doc/gopher.nvim.txt
···
16
16
Generating unit tests boilerplate......................|gopher.nvim-gotests|
17
17
Iferr....................................................|gopher.nvim-iferr|
18
18
Generate comments.....................................|gopher.nvim-comments|
19
-
Setup `nvim-dap` for Go......................................|gopher.nvim-dap|
20
19
21
20
------------------------------------------------------------------------------
22
21
*gopher.nvim-setup*
···
28
27
Usage ~
29
28
`require("gopher").setup {}` (replace `{}` with your `config` table)
30
29
Parameters ~
31
-
{user_config} gopher.Config
30
+
{user_config} `(gopher.Config)`
32
31
33
32
------------------------------------------------------------------------------
34
33
*gopher.nvim-install-deps*
···
204
203
Usage ~
205
204
Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line.
206
205
This module provides a way to generate comments for Go code.
207
-
208
-
209
-
==============================================================================
210
-
------------------------------------------------------------------------------
211
-
*gopher.nvim-dap*
212
-
This module sets up `nvim-dap` for Go.
213
-
Usage ~
214
-
just call `require("gopher.dap").setup()`, and you're good to go.
215
206
216
207
217
208
vim:tw=78:ts=8:noet:ft=help:norl:
-129
lua/gopher/dap.lua
-129
lua/gopher/dap.lua
···
1
-
---@toc_entry Setup `nvim-dap` for Go
2
-
---@tag gopher.nvim-dap
3
-
---@text This module sets up `nvim-dap` for Go.
4
-
---@usage just call `require("gopher.dap").setup()`, and you're good to go.
5
-
6
-
local c = require "gopher.config"
7
-
local dap = {}
8
-
9
-
dap.adapter = function(callback, config)
10
-
local host = config.host or "127.0.0.1"
11
-
local port = config.port or "38697"
12
-
local addr = string.format("%s:%s", host, port)
13
-
14
-
local handle, pid_or_err
15
-
local stdout = assert(vim.loop.new_pipe(false))
16
-
local opts = {
17
-
stdio = { nil, stdout },
18
-
args = { "dap", "-l", addr },
19
-
detached = true,
20
-
}
21
-
22
-
handle, pid_or_err = vim.loop.spawn(c.commands.dlv, opts, function(status)
23
-
if not stdout or not handle then
24
-
return
25
-
end
26
-
27
-
stdout:close()
28
-
handle:close()
29
-
if status ~= 0 then
30
-
print("dlv exited with code", status)
31
-
end
32
-
end)
33
-
34
-
assert(handle, "Error running dlv: " .. tostring(pid_or_err))
35
-
if stdout then
36
-
stdout:read_start(function(err, chunk)
37
-
assert(not err, err)
38
-
if chunk then
39
-
vim.schedule(function()
40
-
require("dap.repl").append(chunk)
41
-
end)
42
-
end
43
-
end)
44
-
end
45
-
46
-
-- wait for delve to start
47
-
vim.defer_fn(function()
48
-
callback { type = "server", host = "127.0.0.1", port = port }
49
-
end, 100)
50
-
end
51
-
52
-
local function args_input()
53
-
vim.ui.input({ prompt = "Args: " }, function(input)
54
-
return vim.split(input or "", " ")
55
-
end)
56
-
end
57
-
58
-
local function get_arguments()
59
-
local co = coroutine.running()
60
-
if co then
61
-
return coroutine.create(function()
62
-
local args = args_input()
63
-
coroutine.resume(co, args)
64
-
end)
65
-
else
66
-
return args_input()
67
-
end
68
-
end
69
-
70
-
dap.configuration = {
71
-
{
72
-
type = "go",
73
-
name = "Debug",
74
-
request = "launch",
75
-
program = "${file}",
76
-
},
77
-
{
78
-
type = "go",
79
-
name = "Debug (Arguments)",
80
-
request = "launch",
81
-
program = "${file}",
82
-
args = get_arguments,
83
-
},
84
-
{
85
-
type = "go",
86
-
name = "Debug Package",
87
-
request = "launch",
88
-
program = "${fileDirname}",
89
-
},
90
-
{
91
-
type = "go",
92
-
name = "Attach",
93
-
mode = "local",
94
-
request = "attach",
95
-
processId = require("dap.utils").pick_process,
96
-
},
97
-
{
98
-
type = "go",
99
-
name = "Debug test",
100
-
request = "launch",
101
-
mode = "test",
102
-
program = "${file}",
103
-
},
104
-
{
105
-
type = "go",
106
-
name = "Debug test (go.mod)",
107
-
request = "launch",
108
-
mode = "test",
109
-
program = "./${relativeFileDirname}",
110
-
},
111
-
}
112
-
113
-
-- sets ups nvim-dap for Go in one function call.
114
-
function dap.setup()
115
-
vim.deprecate(
116
-
"gopher.dap",
117
-
"you might consider setting up `nvim-dap` manually, or using another plugin(https://github.com/leoluz/nvim-dap-go)",
118
-
"v0.1.6",
119
-
"gopher"
120
-
)
121
-
122
-
local ok, d = pcall(require, "dap")
123
-
assert(ok, "gopher.nvim dependency error: dap not installed")
124
-
125
-
d.adapters.go = dap.adapter
126
-
d.configurations.go = dap.configuration
127
-
end
128
-
129
-
return dap
-1
lua/gopher/health.lua
-1
lua/gopher/health.lua
···
22
22
msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`",
23
23
optional = false,
24
24
},
25
-
{ bin = cmd.dlv, msg = "required for debugging, (`nvim-dap`, `gopher.dap`)", optional = true },
26
25
},
27
26
treesitter = {
28
27
{ parser = "go", msg = "required for `gopher.nvim`", optional = false },
-1
lua/gopher/installer.lua
-1
lua/gopher/installer.lua