[mirror] Make your go dev experience better
github.com/olexsmir/gopher.nvim
neovim
golang
1*gopher.nvim* Enhance your golang experience
2
3MIT License Copyright (c) 2025 Oleksandr Smirnov
4
5==============================================================================
6
7gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua.
8It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim.
9
10Table of Contents
11 Setup ................................................ |gopher.nvim-setup()|
12 Install dependencies ............................ |gopher.nvim-dependencies|
13 Config ................................................ |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|
28
29Usage ~
30>lua
31 require("gopher").setup {} -- use default config or replace {} with your own
32<
33Parameters ~
34{user_config} `(gopher.Config)` See |gopher.nvim-config|
35
36------------------------------------------------------------------------------
37 *gopher.nvim-dependencies*
38 `gopher.install_deps`
39Gopher.nvim implements most of its features using third-party tools.
40To install these tools, you can run `:GoInstallDeps` command
41or call `require("gopher").install_deps()` if you want to use lua api.
42By default dependencies will be installed asynchronously,
43to install them synchronously pass `{sync = true}` as an argument.
44
45
46==============================================================================
47------------------------------------------------------------------------------
48 *gopher.nvim-config*
49 `default_config`
50>lua
51 local default_config = {
52 -- log level, you might consider using DEBUG or TRACE for debugging the plugin
53 ---@type number
54 log_level = vim.log.levels.INFO,
55
56 -- timeout for running internal commands
57 ---@type number
58 timeout = 2000,
59
60 --- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
61 installer_timeout = 999999,
62
63 -- user specified paths to binaries
64 ---@class gopher.ConfigCommand
65 commands = {
66 go = "go",
67 gomodifytags = "gomodifytags",
68 gotests = "gotests",
69 impl = "impl",
70 iferr = "iferr",
71 },
72 ---@class gopher.ConfigGotests
73 gotests = {
74 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
75 template = "default",
76 -- path to a directory containing custom test code templates
77 ---@type string|nil
78 template_dir = nil,
79 -- switch table tests from using slice to map (with test name for the key)
80 named = false,
81 },
82 ---@class gopher.ConfigGoTag
83 gotag = {
84 ---@type gopher.ConfigGoTagTransform
85 transform = "snakecase",
86
87 -- default tags to add to struct fields
88 default_tag = "json",
89 },
90 iferr = {
91 -- choose a custom error message
92 ---@type string|nil
93 message = nil,
94 },
95 }
96<
97Class ~
98{gopher.Config}
99
100
101==============================================================================
102------------------------------------------------------------------------------
103 *gopher.nvim-commands*
104
105If don't want to automatically register plugins' commands,
106you can set `vim.g.gopher_register_commands` to `false`, before loading the plugin.
107
108
109==============================================================================
110------------------------------------------------------------------------------
111 *gopher.nvim-struct-tags*
112
113`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
114
115Usage ~
116
117How to add/remove tags to struct fields:
1181. Place cursor on the struct
1192. Run `:GoTagAdd json` to add json tags to struct fields
1203. Run `:GoTagRm json` to remove json tags to struct fields
121
122To clear all tags from struct run: `:GoTagClear`
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==============================================================================
144------------------------------------------------------------------------------
145 *gopher.nvim-impl*
146
147Integration of `impl` tool to generate method stubs for interfaces.
148
149Usage ~
1501. Automatically implement an interface for a struct:
151 - Place your cursor on the struct where you want to implement the interface.
152 - Run `:GoImpl io.Reader`
153 - This will automatically determine the receiver and implement the `io.Reader` interface.
154
1552. Specify a custom receiver:
156 - Place your cursor on the struct
157 - Run `:GoImpl w io.Writer`, where:
158 - `w` is the receiver.
159 - `io.Writer` is the interface to implement.
160
1613. Explicitly specify the receiver, struct, and interface:
162 - No need to place the cursor on the struct if all arguments are provided.
163 - Run `:GoImpl r RequestReader io.Reader`, where:
164 - `r` is the receiver.
165 - `RequestReader` is the struct.
166 - `io.Reader` is the interface to implement.
167
168Example:
169>go
170 type BytesReader struct{}
171 // ^ put your cursor here
172 // run `:GoImpl b io.Reader`
173
174 // this is what you will get
175 func (b *BytesReader) Read(p []byte) (n int, err error) {
176 panic("not implemented") // TODO: Implement
177 }
178<
179
180==============================================================================
181------------------------------------------------------------------------------
182 *gopher.nvim-gotests*
183gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
184Usage ~
185
186- Generate unit test for specific function/method:
187 1. Place your cursor on the desired function/method.
188 2. Run `:GoTestAdd`
189
190- Generate unit tests for *all* functions/methods in current file:
191 - run `:GoTestsAll`
192
193- Generate unit tests *only* for *exported(public)* functions/methods:
194 - run `:GoTestsExp`
195
196You can also specify the template to use for generating the tests. See |gopher.nvim-config|
197More details about templates can be found at: https://github.com/cweill/gotests
198
199If you prefer named tests, you can enable them in |gopher.nvim-config|.
200
201
202==============================================================================
203------------------------------------------------------------------------------
204 *gopher.nvim-iferr*
205
206`iferr` provides a way to way to automatically insert `if err != nil` check.
207If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config|
208
209Usage ~
210Execute `:GoIfErr` near any `err` variable to insert the check
211
212
213==============================================================================
214------------------------------------------------------------------------------
215 *gopher.nvim-comments*
216
217This module provides a way to generate comments for Go code.
218
219Usage ~
220Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
221
222
223 vim:tw=78:ts=8:noet:ft=help:norl: