···2525 dependencies = {
2626 "nvim-lua/plenary.nvim",
2727 "nvim-treesitter/nvim-treesitter",
2828- "mfussenegger/nvim-dap", -- (optional) only if you use `gopher.dap`
2928 },
3029 -- (optional) will update plugin's deps on every update
3130 build = function()
···216215 ```
217216</details>
218217219219-<details>
220220- <summary>
221221- <b>Setup <a href="https://github.com/mfussenegger/nvim-dap">nvim-dap</a> for go in one line</b>
222222- </summary>
223223-224224- THIS FEATURE WILL BE REMOVED IN `0.1.6`
225225-226226- note [nvim-dap](https://github.com/mfussenegger/nvim-dap) has to be installed
227227-228228- ```lua
229229- require("gopher.dap").setup()
230230- ```
231231-</details>
232232-233218## Contributing
234219235220PRs are always welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md)
···237222## Thanks
238223239224- [go.nvim](https://github.com/ray-x/go.nvim)
240240-- [nvim-dap-go](https://github.com/leoluz/nvim-dap-go)
241225- [iferr](https://github.com/koron/iferr)
+1-10
doc/gopher.nvim.txt
···1616 Generating unit tests boilerplate......................|gopher.nvim-gotests|
1717 Iferr....................................................|gopher.nvim-iferr|
1818 Generate comments.....................................|gopher.nvim-comments|
1919- Setup `nvim-dap` for Go......................................|gopher.nvim-dap|
20192120------------------------------------------------------------------------------
2221 *gopher.nvim-setup*
···2827Usage ~
2928`require("gopher").setup {}` (replace `{}` with your `config` table)
3029Parameters ~
3131-{user_config} gopher.Config
3030+{user_config} `(gopher.Config)`
32313332------------------------------------------------------------------------------
3433 *gopher.nvim-install-deps*
···204203Usage ~
205204Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line.
206205This module provides a way to generate comments for Go code.
207207-208208-209209-==============================================================================
210210-------------------------------------------------------------------------------
211211- *gopher.nvim-dap*
212212-This module sets up `nvim-dap` for Go.
213213-Usage ~
214214-just call `require("gopher.dap").setup()`, and you're good to go.
215206216207217208 vim:tw=78:ts=8:noet:ft=help:norl:
-129
lua/gopher/dap.lua
···11----@toc_entry Setup `nvim-dap` for Go
22----@tag gopher.nvim-dap
33----@text This module sets up `nvim-dap` for Go.
44----@usage just call `require("gopher.dap").setup()`, and you're good to go.
55-66-local c = require "gopher.config"
77-local dap = {}
88-99-dap.adapter = function(callback, config)
1010- local host = config.host or "127.0.0.1"
1111- local port = config.port or "38697"
1212- local addr = string.format("%s:%s", host, port)
1313-1414- local handle, pid_or_err
1515- local stdout = assert(vim.loop.new_pipe(false))
1616- local opts = {
1717- stdio = { nil, stdout },
1818- args = { "dap", "-l", addr },
1919- detached = true,
2020- }
2121-2222- handle, pid_or_err = vim.loop.spawn(c.commands.dlv, opts, function(status)
2323- if not stdout or not handle then
2424- return
2525- end
2626-2727- stdout:close()
2828- handle:close()
2929- if status ~= 0 then
3030- print("dlv exited with code", status)
3131- end
3232- end)
3333-3434- assert(handle, "Error running dlv: " .. tostring(pid_or_err))
3535- if stdout then
3636- stdout:read_start(function(err, chunk)
3737- assert(not err, err)
3838- if chunk then
3939- vim.schedule(function()
4040- require("dap.repl").append(chunk)
4141- end)
4242- end
4343- end)
4444- end
4545-4646- -- wait for delve to start
4747- vim.defer_fn(function()
4848- callback { type = "server", host = "127.0.0.1", port = port }
4949- end, 100)
5050-end
5151-5252-local function args_input()
5353- vim.ui.input({ prompt = "Args: " }, function(input)
5454- return vim.split(input or "", " ")
5555- end)
5656-end
5757-5858-local function get_arguments()
5959- local co = coroutine.running()
6060- if co then
6161- return coroutine.create(function()
6262- local args = args_input()
6363- coroutine.resume(co, args)
6464- end)
6565- else
6666- return args_input()
6767- end
6868-end
6969-7070-dap.configuration = {
7171- {
7272- type = "go",
7373- name = "Debug",
7474- request = "launch",
7575- program = "${file}",
7676- },
7777- {
7878- type = "go",
7979- name = "Debug (Arguments)",
8080- request = "launch",
8181- program = "${file}",
8282- args = get_arguments,
8383- },
8484- {
8585- type = "go",
8686- name = "Debug Package",
8787- request = "launch",
8888- program = "${fileDirname}",
8989- },
9090- {
9191- type = "go",
9292- name = "Attach",
9393- mode = "local",
9494- request = "attach",
9595- processId = require("dap.utils").pick_process,
9696- },
9797- {
9898- type = "go",
9999- name = "Debug test",
100100- request = "launch",
101101- mode = "test",
102102- program = "${file}",
103103- },
104104- {
105105- type = "go",
106106- name = "Debug test (go.mod)",
107107- request = "launch",
108108- mode = "test",
109109- program = "./${relativeFileDirname}",
110110- },
111111-}
112112-113113--- sets ups nvim-dap for Go in one function call.
114114-function dap.setup()
115115- vim.deprecate(
116116- "gopher.dap",
117117- "you might consider setting up `nvim-dap` manually, or using another plugin(https://github.com/leoluz/nvim-dap-go)",
118118- "v0.1.6",
119119- "gopher"
120120- )
121121-122122- local ok, d = pcall(require, "dap")
123123- assert(ok, "gopher.nvim dependency error: dap not installed")
124124-125125- d.adapters.go = dap.adapter
126126- d.configurations.go = dap.configuration
127127-end
128128-129129-return dap