[mirror] Make your go dev experience better
github.com/olexsmir/gopher.nvim
neovim
golang
1*gopher.nvim*
2
3==============================================================================
4
5gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua.
6It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim.
7
8------------------------------------------------------------------------------
9 *gopher.nvim-table-of-contents*
10Table of Contents
11 Setup....................................................|gopher.nvim-setup|
12 Install dependencies..............................|gopher.nvim-install-deps|
13 Configuration...........................................|gopher.nvim-config|
14 Commands..............................................|gopher.nvim-commands|
15 Modify struct tags.................................|gopher.nvim-struct-tags|
16 Auto implementation of interface methods..................|gopher.nvim-impl|
17 Generating unit tests boilerplate......................|gopher.nvim-gotests|
18 Iferr....................................................|gopher.nvim-iferr|
19 Generate comments.....................................|gopher.nvim-comments|
20
21------------------------------------------------------------------------------
22 *gopher.nvim-setup*
23 `gopher.setup`({user_config})
24Setup function. This method simply merges default config with opts table.
25You can read more about configuration at |gopher.nvim-config|
26Calling this function is optional, if you ok with default settings.
27See |gopher.nvim.config-defaults|
28
29Usage ~
30`require("gopher").setup {}` (replace `{}` with your `config` table)
31Parameters ~
32{user_config} `(gopher.Config)`
33
34------------------------------------------------------------------------------
35 *gopher.nvim-install-deps*
36 `gopher.install_deps`
37Gopher.nvim implements most of its features using third-party tools.
38To install these tools, you can run `:GoInstallDeps` command
39or call `require("gopher").install_deps()` if you want to use lua api.
40By default dependencies will be installed asynchronously,
41to install them synchronously pass `{sync = true}` as an argument.
42
43
44==============================================================================
45------------------------------------------------------------------------------
46 *gopher.nvim-config*
47config it is the place where you can configure the plugin.
48also this is optional is you're ok with default settings.
49You can look at default options |gopher.nvim-config-defaults|
50
51------------------------------------------------------------------------------
52 *gopher.nvim-config-defaults*
53 `default_config`
54>lua
55 local default_config = {
56 --minidoc_replace_end
57
58 -- log level, you might consider using DEBUG or TRACE for debugging the plugin
59 ---@type number
60 log_level = vim.log.levels.INFO,
61
62 -- timeout for running internal commands
63 ---@type number
64 timeout = 2000,
65
66 -- user specified paths to binaries
67 ---@class gopher.ConfigCommand
68 commands = {
69 go = "go",
70 gomodifytags = "gomodifytags",
71 gotests = "gotests",
72 impl = "impl",
73 iferr = "iferr",
74 },
75 ---@class gopher.ConfigGotests
76 gotests = {
77 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
78 template = "default",
79 -- path to a directory containing custom test code templates
80 ---@type string|nil
81 template_dir = nil,
82 -- switch table tests from using slice to map (with test name for the key)
83 named = false,
84 },
85 ---@class gopher.ConfigGoTag
86 gotag = {
87 ---@type gopher.ConfigGoTagTransform
88 transform = "snakecase",
89
90 -- default tags to add to struct fields
91 default_tag = "json",
92 },
93 iferr = {
94 -- choose a custom error message
95 ---@type string|nil
96 message = nil,
97 },
98 }
99<
100Class ~
101{gopher.Config}
102
103
104==============================================================================
105------------------------------------------------------------------------------
106 *gopher.nvim-commands*
107
108If don't want to automatically register plugins' commands,
109you can set `vim.g.gopher_register_commands` to `false`, before loading the plugin.
110
111
112==============================================================================
113------------------------------------------------------------------------------
114 *gopher.nvim-struct-tags*
115struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
116Usage ~
117
118How to add/remove tags to struct fields:
119
120------------------------------------------------------------------------------
1212. Run `:GoTagAdd json` to add json tags to struct fields
1223. Run `:GoTagRm json` to remove json tags to struct fields
123
124NOTE: if you dont specify the tag it will use `json` as default
125
126Example:
127>go
128 // before
129 type User struct {
130 // ^ put your cursor here
131 // run `:GoTagAdd yaml`
132 ID int
133 Name string
134 }
135
136 // after
137 type User struct {
138 ID int `yaml:id`
139 Name string `yaml:name`
140 }
141<
142------------------------------------------------------------------------------
143 *struct_tags.add()*
144 `struct_tags.add`({...})
145tags to a struct under the cursor
146Parameters ~
147{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
148
149------------------------------------------------------------------------------
150 *struct_tags.remove()*
151 `struct_tags.remove`({...})
152tags from a struct under the cursor
153Parameters ~
154{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
155
156------------------------------------------------------------------------------
157 *struct_tags.clear()*
158 `struct_tags.clear`()
159all tags from a struct under the cursor
160
161
162==============================================================================
163------------------------------------------------------------------------------
164 *gopher.nvim-impl*
165impl is utilizing the `impl` tool to generate method stubs for interfaces.
166Usage ~
167
1681. Automatically implement an interface for a struct:
169 - Place your cursor on the struct where you want to implement the interface.
170 - Run `:GoImpl io.Reader`
171 - This will automatically determine the receiver and implement the `io.Reader` interface.
172
1732. Specify a custom receiver:
174 - Place your cursor on the struct
175 - Run `:GoImpl w io.Writer`, where:
176 - `w` is the receiver.
177 - `io.Writer` is the interface to implement.
178
1793. Explicitly specify the receiver, struct, and interface:
180 - No need to place the cursor on the struct if all arguments are provided.
181 - Run `:GoImpl r RequestReader io.Reader`, where:
182 - `r` is the receiver.
183 - `RequestReader` is the struct.
184 - `io.Reader` is the interface to implement.
185
186Example:
187>go
188 type BytesReader struct{}
189 // ^ put your cursor here
190 // run `:GoImpl b io.Reader`
191
192 // this is what you will get
193 func (b *BytesReader) Read(p []byte) (n int, err error) {
194 panic("not implemented") // TODO: Implement
195 }
196<
197
198==============================================================================
199------------------------------------------------------------------------------
200 *gopher.nvim-gotests*
201gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
202Usage ~
203
204- Generate unit test for specific function/method:
205 1. Place your cursor on the desired function/method.
206 2. Run `:GoTestAdd`
207
208- Generate unit tests for *all* functions/methods in current file:
209 - run `:GoTestsAll`
210
211- Generate unit tests *only* for *exported(public)* functions/methods:
212 - run `:GoTestsExp`
213
214You can also specify the template to use for generating the tests. See |gopher.nvim-config|
215More details about templates can be found at: https://github.com/cweill/gotests
216
217------------------------------------------------------------------------------
218 *gopher.nvim-gotests-named*
219
220You can enable named tests in the config if you prefer using named tests.
221See |gopher.nvim-config|.
222
223
224==============================================================================
225------------------------------------------------------------------------------
226 *gopher.nvim-iferr*
227If you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check.
228Usage ~
229Execute `:GoIfErr` near any `err` variable to insert the check
230
231
232==============================================================================
233------------------------------------------------------------------------------
234 *gopher.nvim-comments*
235Usage ~
236Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line.
237This module provides a way to generate comments for Go code.
238
239
240 vim:tw=78:ts=8:noet:ft=help:norl: