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