···2424- [Go](https://github.com/golang/go) installed
25252626```lua
2727--- NOTE: this plugin is already lazy-loaded, it adds only about 1ms of load
2828--- time to your config
2727+-- NOTE: the plugin is already lazy-loaded
2828+-- it adds ~1ms to startup time
2929{
3030 "olexsmir/gopher.nvim",
3131 ft = "go",
···217217 -- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
218218 restart_lsp = false,
219219220220+ -- user specified paths to binaries
220221 commands = {
221222 go = "go",
222223 gomodifytags = "gomodifytags",
···225226 iferr = "iferr",
226227 },
227228 gotests = {
228228- -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
229229+ -- a default template that gotess will use.
230230+ -- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
229231 template = "default",
232232+230233 -- path to a directory containing custom test code templates
231234 template_dir = nil,
232232- -- switch table tests from using slice to map (with test name for the key)
235235+236236+ -- use named tests(map with test name as key) in table tests(slice of structs by default)
233237 named = false,
234238 },
235239 gotag = {
236240 transform = "snakecase",
241241+237242 -- default tags to add to struct fields
238243 default_tag = "json",
244244+239245 -- default tag option added struct fields, set to nil to disable
246246+ -- e.g: `option = "json=omitempty,xml=omitempty`
240247 option = nil,
241248 },
242249 iferr = {
243243- -- choose a custom error message
250250+ -- choose a custom error message, nil to use default
251251+ -- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
244252 message = nil,
245253 },
246254}
+43-31
doc/gopher.nvim.txt
···3636------------------------------------------------------------------------------
3737 *gopher.nvim-dependencies*
3838 `gopher.install_deps`
3939-Gopher.nvim implements most of its features using third-party tools.
4040-To install these tools, you can run `:GoInstallDeps` command
4141-or call `require("gopher").install_deps()` if you want to use lua api.
4242-By default dependencies will be installed asynchronously,
4343-to install them synchronously pass `{sync = true}` as an argument.
3939+4040+Gopher.nvim implements most of its features using third-party tools. To
4141+install plugin's dependencies, you can run:
4242+`:GoInstallDeps` or `:GoInstallDepsSync`
4343+or use `require("gopher").install_deps()` if you prefer lua api.
444445454646==============================================================================
···5858 timeout = 2000,
59596060 -- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
6161+ ---@type number
6162 installer_timeout = 999999,
62636364 -- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
···7475 },
7576 ---@class gopher.ConfigGotests
7677 gotests = {
7777- -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
7878+ -- a default template that gotess will use.
7979+ -- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
7880 template = "default",
8181+7982 -- path to a directory containing custom test code templates
8083 ---@type string|nil
8184 template_dir = nil,
8282- -- switch table tests from using slice to map (with test name for the key)
8585+8686+ -- use named tests(map with test name as key) in table tests(slice of structs by default)
8387 named = false,
8488 },
8589 ---@class gopher.ConfigGoTag
···9195 default_tag = "json",
92969397 -- default tag option added struct fields, set to nil to disable
9898+ -- e.g: `option = "json=omitempty,xml=omitempty`
9499 ---@type string|nil
95100 option = nil,
96101 },
97102 iferr = {
9898- -- choose a custom error message
103103+ -- choose a custom error message, nil to use default
104104+ -- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
99105 ---@type string|nil
100106 message = nil,
101107 },
···119125------------------------------------------------------------------------------
120126 *gopher.nvim-struct-tags*
121127122122-`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
128128+`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to
129129+struct fields.
123130124131Usage ~
125132126126-How to add/remove tags to struct fields:
133133+How to add/remove/clear tags to struct fields:
1271341. Place cursor on the struct
1281352. Run `:GoTagAdd json` to add json tags to struct fields
1291363. Run `:GoTagRm json` to remove json tags to struct fields
137137+4. Run `:GoTagClear` to clear all tags from struct fields
130138131131-If you want to add/remove tag with options, you can use `json=omitempty` (where json is tag, and omitempty is its option).
139139+If you want to add/remove tag with options, you can use `json=omitempty`
140140+(where json is tag, and omitempty is its option).
132141Example: `:GoTagAdd xml json=omitempty`
133142134134-To clear all tags from struct run: `:GoTagClear`
135143136144NOTE: if you dont specify the tag it will use `json` as default
137145···159167Integration of `impl` tool to generate method stubs for interfaces.
160168161169Usage ~
170170+1621711. Automatically implement an interface for a struct:
163163- - Place your cursor on the struct where you want to implement the interface.
164164- - Run `:GoImpl io.Reader`
165165- - This will automatically determine the receiver and implement the `io.Reader` interface.
172172+ - Place your cursor on the struct where you want to implement the interface.
173173+ - Run `:GoImpl io.Reader`
174174+ - This will automatically determine the receiver and implement the `io.Reader` interface.
1661751671762. Specify a custom receiver:
168168- - Place your cursor on the struct
169169- - Run `:GoImpl w io.Writer`, where:
170170- - `w` is the receiver.
171171- - `io.Writer` is the interface to implement.
177177+ - Place your cursor on the struct
178178+ - Run `:GoImpl w io.Writer`, where:
179179+ - `w` is the receiver.
180180+ - `io.Writer` is the interface to implement.
1721811731823. Explicitly specify the receiver, struct, and interface:
174174- - No need to place the cursor on the struct if all arguments are provided.
175175- - Run `:GoImpl r RequestReader io.Reader`, where:
176176- - `r` is the receiver.
177177- - `RequestReader` is the struct.
178178- - `io.Reader` is the interface to implement.
183183+ - No need to place the cursor on the struct if all arguments are provided.
184184+ - Run `:GoImpl r RequestReader io.Reader`, where:
185185+ - `r` is the receiver.
186186+ - `RequestReader` is the struct.
187187+ - `io.Reader` is the interface to implement.
179188180189Example:
181190>go
···196205Usage ~
197206198207- Generate unit test for specific function/method:
199199- 1. Place your cursor on the desired function/method.
200200- 2. Run `:GoTestAdd`
208208+ 1. Place your cursor on the desired function/method.
209209+ 2. Run `:GoTestAdd`
201210202211- Generate unit tests for *all* functions/methods in current file:
203203- - run `:GoTestsAll`
212212+ - run `:GoTestsAll`
204213205214- Generate unit tests *only* for *exported(public)* functions/methods:
206206- - run `:GoTestsExp`
215215+ - run `:GoTestsExp`
207216208208-You can also specify the template to use for generating the tests. See |gopher.nvim-config|
209209-More details about templates can be found at: https://github.com/cweill/gotests
217217+You can also specify the template to use for generating the tests.
218218+See |gopher.nvim-config|.
219219+More details about templates: https://github.com/cweill/gotests
210220211221If you prefer named tests, you can enable them in |gopher.nvim-config|.
212222···229239This module provides a way to generate comments for Go code.
230240231241Usage ~
232232-Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
242242+243243+Set cursor on line with function/method/struct/etc and
244244+run `:GoCmt` to generate a comment.
233245234246235247 vim:tw=78:ts=8:noet:ft=help:norl:
+3-1
lua/gopher/comment.lua
···33---@text
44--- This module provides a way to generate comments for Go code.
55---
66----@usage Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
66+---@usage
77+--- Set cursor on line with function/method/struct/etc and
88+--- run `:GoCmt` to generate a comment.
79810local ts = require "gopher._utils.ts"
911local log = require "gopher._utils.log"
+9-3
lua/gopher/config.lua
···3030 timeout = 2000,
31313232 -- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
3333+ ---@type number
3334 installer_timeout = 999999,
34353536 -- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
···4647 },
4748 ---@class gopher.ConfigGotests
4849 gotests = {
4949- -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
5050+ -- a default template that gotess will use.
5151+ -- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
5052 template = "default",
5353+5154 -- path to a directory containing custom test code templates
5255 ---@type string|nil
5356 template_dir = nil,
5454- -- switch table tests from using slice to map (with test name for the key)
5757+5858+ -- use named tests(map with test name as key) in table tests(slice of structs by default)
5559 named = false,
5660 },
5761 ---@class gopher.ConfigGoTag
···6367 default_tag = "json",
64686569 -- default tag option added struct fields, set to nil to disable
7070+ -- e.g: `option = "json=omitempty,xml=omitempty`
6671 ---@type string|nil
6772 option = nil,
6873 },
6974 iferr = {
7070- -- choose a custom error message
7575+ -- choose a custom error message, nil to use default
7676+ -- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
7177 ---@type string|nil
7278 message = nil,
7379 },
+7-6
lua/gopher/gotests.lua
···33---@text gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
44---@usage
55--- - Generate unit test for specific function/method:
66---- 1. Place your cursor on the desired function/method.
77---- 2. Run `:GoTestAdd`
66+--- 1. Place your cursor on the desired function/method.
77+--- 2. Run `:GoTestAdd`
88---
99--- - Generate unit tests for *all* functions/methods in current file:
1010---- - run `:GoTestsAll`
1010+--- - run `:GoTestsAll`
1111---
1212--- - Generate unit tests *only* for *exported(public)* functions/methods:
1313---- - run `:GoTestsExp`
1313+--- - run `:GoTestsExp`
1414---
1515---- You can also specify the template to use for generating the tests. See |gopher.nvim-config|
1616---- More details about templates can be found at: https://github.com/cweill/gotests
1515+--- You can also specify the template to use for generating the tests.
1616+--- See |gopher.nvim-config|.
1717+--- More details about templates: https://github.com/cweill/gotests
1718---
1819--- If you prefer named tests, you can enable them in |gopher.nvim-config|.
1920
+14-13
lua/gopher/impl.lua
···33---@text
44--- Integration of `impl` tool to generate method stubs for interfaces.
55---
66----@usage 1. Automatically implement an interface for a struct:
77---- - Place your cursor on the struct where you want to implement the interface.
88---- - Run `:GoImpl io.Reader`
99---- - This will automatically determine the receiver and implement the `io.Reader` interface.
66+---@usage
77+--- 1. Automatically implement an interface for a struct:
88+--- - Place your cursor on the struct where you want to implement the interface.
99+--- - Run `:GoImpl io.Reader`
1010+--- - This will automatically determine the receiver and implement the `io.Reader` interface.
1011---
1112--- 2. Specify a custom receiver:
1212---- - Place your cursor on the struct
1313---- - Run `:GoImpl w io.Writer`, where:
1414---- - `w` is the receiver.
1515---- - `io.Writer` is the interface to implement.
1313+--- - Place your cursor on the struct
1414+--- - Run `:GoImpl w io.Writer`, where:
1515+--- - `w` is the receiver.
1616+--- - `io.Writer` is the interface to implement.
1617---
1718--- 3. Explicitly specify the receiver, struct, and interface:
1818---- - No need to place the cursor on the struct if all arguments are provided.
1919---- - Run `:GoImpl r RequestReader io.Reader`, where:
2020---- - `r` is the receiver.
2121---- - `RequestReader` is the struct.
2222---- - `io.Reader` is the interface to implement.
1919+--- - No need to place the cursor on the struct if all arguments are provided.
2020+--- - Run `:GoImpl r RequestReader io.Reader`, where:
2121+--- - `r` is the receiver.
2222+--- - `RequestReader` is the struct.
2323+--- - `io.Reader` is the interface to implement.
2324---
2425--- Example:
2526--- >go
+5-5
lua/gopher/init.lua
···35353636---@toc_entry Install dependencies
3737---@tag gopher.nvim-dependencies
3838----@text Gopher.nvim implements most of its features using third-party tools.
3939---- To install these tools, you can run `:GoInstallDeps` command
4040---- or call `require("gopher").install_deps()` if you want to use lua api.
4141---- By default dependencies will be installed asynchronously,
4242---- to install them synchronously pass `{sync = true}` as an argument.
3838+---@text
3939+--- Gopher.nvim implements most of its features using third-party tools. To
4040+--- install plugin's dependencies, you can run:
4141+--- `:GoInstallDeps` or `:GoInstallDepsSync`
4242+--- or use `require("gopher").install_deps()` if you prefer lua api.
4343gopher.install_deps = require("gopher.installer").install_deps
44444545gopher.impl = require("gopher.impl").impl
+10-10
lua/gopher/struct_tags.lua
···11---@toc_entry Modify struct tags
22---@tag gopher.nvim-struct-tags
33---@text
44---- `struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
44+--- `struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to
55+--- struct fields.
56---
67---@usage
77---- How to add/remove tags to struct fields:
88+--- How to add/remove/clear tags to struct fields:
89--- 1. Place cursor on the struct
910--- 2. Run `:GoTagAdd json` to add json tags to struct fields
1011--- 3. Run `:GoTagRm json` to remove json tags to struct fields
1212+--- 4. Run `:GoTagClear` to clear all tags from struct fields
1113---
1212---- If you want to add/remove tag with options, you can use `json=omitempty` (where json is tag, and omitempty is its option).
1414+--- If you want to add/remove tag with options, you can use `json=omitempty`
1515+--- (where json is tag, and omitempty is its option).
1316--- Example: `:GoTagAdd xml json=omitempty`
1417---
1515---- To clear all tags from struct run: `:GoTagClear`
1618---
1719--- NOTE: if you dont specify the tag it will use `json` as default
1820---
···150152 }
151153end
152154153153--- Adds tags to a struct under the cursor
154154--- See `:h gopher.nvim-struct-tags`
155155+-- Adds tags to a struct under the cursor. See `:h gopher.nvim-struct-tags`.
155156---@param opts gopher.StructTagInput
156157---@dochide
157158function struct_tags.add(opts)
···169170 })
170171end
171172172172--- Removes tags from a struct under the cursor
173173--- See `:h gopher.nvim-struct-tags`
173173+-- Removes tags from a struct under the cursor. See `:h gopher.nvim-struct-tags`.
174174---@dochide
175175---@param opts gopher.StructTagInput
176176function struct_tags.remove(opts)
···188188 })
189189end
190190191191--- Removes all tags from a struct under the cursor
192192--- See `:h gopher.nvim-struct-tags`
191191+-- Removes all tags from a struct under the cursor.
192192+-- See `:h gopher.nvim-struct-tags`.
193193---@dochide
194194function struct_tags.clear()
195195 local fpath = vim.fn.expand "%"