[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 -- user specified paths to binaries
61 ---@class gopher.ConfigCommand
62 commands = {
63 go = "go",
64 gomodifytags = "gomodifytags",
65 gotests = "gotests",
66 impl = "impl",
67 iferr = "iferr",
68 },
69 ---@class gopher.ConfigGotests
70 gotests = {
71 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
72 template = "default",
73 -- path to a directory containing custom test code templates
74 ---@type string|nil
75 template_dir = nil,
76 -- switch table tests from using slice to map (with test name for the key)
77 named = false,
78 },
79 ---@class gopher.ConfigGoTag
80 gotag = {
81 ---@type gopher.ConfigGoTagTransform
82 transform = "snakecase",
83
84 -- default tags to add to struct fields
85 default_tag = "json",
86 },
87 iferr = {
88 -- choose a custom error message
89 ---@type string|nil
90 message = nil,
91 },
92 }
93<
94Class ~
95{gopher.Config}
96
97
98==============================================================================
99------------------------------------------------------------------------------
100 *gopher.nvim-commands*
101
102If don't want to automatically register plugins' commands,
103you can set `vim.g.gopher_register_commands` to `false`, before loading the plugin.
104
105
106==============================================================================
107------------------------------------------------------------------------------
108 *gopher.nvim-struct-tags*
109
110`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
111
112Usage ~
113
114How to add/remove tags to struct fields:
1151. Place cursor on the struct
1162. Run `:GoTagAdd json` to add json tags to struct fields
1173. Run `:GoTagRm json` to remove json tags to struct fields
118
119To clear all tags from struct run: `:GoTagClear`
120
121NOTE: if you dont specify the tag it will use `json` as default
122
123Example:
124>go
125 // before
126 type User struct {
127 // ^ put your cursor here
128 // run `:GoTagAdd yaml`
129 ID int
130 Name string
131 }
132
133 // after
134 type User struct {
135 ID int `yaml:id`
136 Name string `yaml:name`
137 }
138<
139
140==============================================================================
141------------------------------------------------------------------------------
142 *gopher.nvim-impl*
143
144Integration of `impl` tool to generate method stubs for interfaces.
145
146Usage ~
1471. Automatically implement an interface for a struct:
148 - Place your cursor on the struct where you want to implement the interface.
149 - Run `:GoImpl io.Reader`
150 - This will automatically determine the receiver and implement the `io.Reader` interface.
151
1522. Specify a custom receiver:
153 - Place your cursor on the struct
154 - Run `:GoImpl w io.Writer`, where:
155 - `w` is the receiver.
156 - `io.Writer` is the interface to implement.
157
1583. Explicitly specify the receiver, struct, and interface:
159 - No need to place the cursor on the struct if all arguments are provided.
160 - Run `:GoImpl r RequestReader io.Reader`, where:
161 - `r` is the receiver.
162 - `RequestReader` is the struct.
163 - `io.Reader` is the interface to implement.
164
165Example:
166>go
167 type BytesReader struct{}
168 // ^ put your cursor here
169 // run `:GoImpl b io.Reader`
170
171 // this is what you will get
172 func (b *BytesReader) Read(p []byte) (n int, err error) {
173 panic("not implemented") // TODO: Implement
174 }
175<
176
177==============================================================================
178------------------------------------------------------------------------------
179 *gopher.nvim-gotests*
180gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
181Usage ~
182
183- Generate unit test for specific function/method:
184 1. Place your cursor on the desired function/method.
185 2. Run `:GoTestAdd`
186
187- Generate unit tests for *all* functions/methods in current file:
188 - run `:GoTestsAll`
189
190- Generate unit tests *only* for *exported(public)* functions/methods:
191 - run `:GoTestsExp`
192
193You can also specify the template to use for generating the tests. See |gopher.nvim-config|
194More details about templates can be found at: https://github.com/cweill/gotests
195
196If you prefer named tests, you can enable them in |gopher.nvim-config|.
197
198
199==============================================================================
200------------------------------------------------------------------------------
201 *gopher.nvim-iferr*
202
203`iferr` provides a way to way to automatically insert `if err != nil` check.
204If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config|
205
206Usage ~
207Execute `:GoIfErr` near any `err` variable to insert the check
208
209
210==============================================================================
211------------------------------------------------------------------------------
212 *gopher.nvim-comments*
213
214This module provides a way to generate comments for Go code.
215
216Usage ~
217Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
218
219
220 vim:tw=78:ts=8:noet:ft=help:norl: