+13
-5
README.md
+13
-5
README.md
···
24
24
- [Go](https://github.com/golang/go) installed
25
25
26
26
```lua
27
-
-- NOTE: this plugin is already lazy-loaded, it adds only about 1ms of load
28
-
-- time to your config
27
+
-- NOTE: the plugin is already lazy-loaded
28
+
-- it adds ~1ms to startup time
29
29
{
30
30
"olexsmir/gopher.nvim",
31
31
ft = "go",
···
217
217
-- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
218
218
restart_lsp = false,
219
219
220
+
-- user specified paths to binaries
220
221
commands = {
221
222
go = "go",
222
223
gomodifytags = "gomodifytags",
···
225
226
iferr = "iferr",
226
227
},
227
228
gotests = {
228
-
-- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
229
+
-- a default template that gotess will use.
230
+
-- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
229
231
template = "default",
232
+
230
233
-- path to a directory containing custom test code templates
231
234
template_dir = nil,
232
-
-- switch table tests from using slice to map (with test name for the key)
235
+
236
+
-- use named tests(map with test name as key) in table tests(slice of structs by default)
233
237
named = false,
234
238
},
235
239
gotag = {
236
240
transform = "snakecase",
241
+
237
242
-- default tags to add to struct fields
238
243
default_tag = "json",
244
+
239
245
-- default tag option added struct fields, set to nil to disable
246
+
-- e.g: `option = "json=omitempty,xml=omitempty`
240
247
option = nil,
241
248
},
242
249
iferr = {
243
-
-- choose a custom error message
250
+
-- choose a custom error message, nil to use default
251
+
-- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
244
252
message = nil,
245
253
},
246
254
}
+43
-31
doc/gopher.nvim.txt
+43
-31
doc/gopher.nvim.txt
···
36
36
------------------------------------------------------------------------------
37
37
*gopher.nvim-dependencies*
38
38
`gopher.install_deps`
39
-
Gopher.nvim implements most of its features using third-party tools.
40
-
To install these tools, you can run `:GoInstallDeps` command
41
-
or call `require("gopher").install_deps()` if you want to use lua api.
42
-
By default dependencies will be installed asynchronously,
43
-
to install them synchronously pass `{sync = true}` as an argument.
39
+
40
+
Gopher.nvim implements most of its features using third-party tools. To
41
+
install plugin's dependencies, you can run:
42
+
`:GoInstallDeps` or `:GoInstallDepsSync`
43
+
or use `require("gopher").install_deps()` if you prefer lua api.
44
44
45
45
46
46
==============================================================================
···
58
58
timeout = 2000,
59
59
60
60
-- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
61
+
---@type number
61
62
installer_timeout = 999999,
62
63
63
64
-- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
···
74
75
},
75
76
---@class gopher.ConfigGotests
76
77
gotests = {
77
-
-- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
78
+
-- a default template that gotess will use.
79
+
-- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
78
80
template = "default",
81
+
79
82
-- path to a directory containing custom test code templates
80
83
---@type string|nil
81
84
template_dir = nil,
82
-
-- switch table tests from using slice to map (with test name for the key)
85
+
86
+
-- use named tests(map with test name as key) in table tests(slice of structs by default)
83
87
named = false,
84
88
},
85
89
---@class gopher.ConfigGoTag
···
91
95
default_tag = "json",
92
96
93
97
-- default tag option added struct fields, set to nil to disable
98
+
-- e.g: `option = "json=omitempty,xml=omitempty`
94
99
---@type string|nil
95
100
option = nil,
96
101
},
97
102
iferr = {
98
-
-- choose a custom error message
103
+
-- choose a custom error message, nil to use default
104
+
-- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
99
105
---@type string|nil
100
106
message = nil,
101
107
},
···
119
125
------------------------------------------------------------------------------
120
126
*gopher.nvim-struct-tags*
121
127
122
-
`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
128
+
`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to
129
+
struct fields.
123
130
124
131
Usage ~
125
132
126
-
How to add/remove tags to struct fields:
133
+
How to add/remove/clear tags to struct fields:
127
134
1. Place cursor on the struct
128
135
2. Run `:GoTagAdd json` to add json tags to struct fields
129
136
3. Run `:GoTagRm json` to remove json tags to struct fields
137
+
4. Run `:GoTagClear` to clear all tags from struct fields
130
138
131
-
If you want to add/remove tag with options, you can use `json=omitempty` (where json is tag, and omitempty is its option).
139
+
If you want to add/remove tag with options, you can use `json=omitempty`
140
+
(where json is tag, and omitempty is its option).
132
141
Example: `:GoTagAdd xml json=omitempty`
133
142
134
-
To clear all tags from struct run: `:GoTagClear`
135
143
136
144
NOTE: if you dont specify the tag it will use `json` as default
137
145
···
159
167
Integration of `impl` tool to generate method stubs for interfaces.
160
168
161
169
Usage ~
170
+
162
171
1. Automatically implement an interface for a struct:
163
-
- Place your cursor on the struct where you want to implement the interface.
164
-
- Run `:GoImpl io.Reader`
165
-
- This will automatically determine the receiver and implement the `io.Reader` interface.
172
+
- Place your cursor on the struct where you want to implement the interface.
173
+
- Run `:GoImpl io.Reader`
174
+
- This will automatically determine the receiver and implement the `io.Reader` interface.
166
175
167
176
2. Specify a custom receiver:
168
-
- Place your cursor on the struct
169
-
- Run `:GoImpl w io.Writer`, where:
170
-
- `w` is the receiver.
171
-
- `io.Writer` is the interface to implement.
177
+
- Place your cursor on the struct
178
+
- Run `:GoImpl w io.Writer`, where:
179
+
- `w` is the receiver.
180
+
- `io.Writer` is the interface to implement.
172
181
173
182
3. Explicitly specify the receiver, struct, and interface:
174
-
- No need to place the cursor on the struct if all arguments are provided.
175
-
- Run `:GoImpl r RequestReader io.Reader`, where:
176
-
- `r` is the receiver.
177
-
- `RequestReader` is the struct.
178
-
- `io.Reader` is the interface to implement.
183
+
- No need to place the cursor on the struct if all arguments are provided.
184
+
- Run `:GoImpl r RequestReader io.Reader`, where:
185
+
- `r` is the receiver.
186
+
- `RequestReader` is the struct.
187
+
- `io.Reader` is the interface to implement.
179
188
180
189
Example:
181
190
>go
···
196
205
Usage ~
197
206
198
207
- Generate unit test for specific function/method:
199
-
1. Place your cursor on the desired function/method.
200
-
2. Run `:GoTestAdd`
208
+
1. Place your cursor on the desired function/method.
209
+
2. Run `:GoTestAdd`
201
210
202
211
- Generate unit tests for *all* functions/methods in current file:
203
-
- run `:GoTestsAll`
212
+
- run `:GoTestsAll`
204
213
205
214
- Generate unit tests *only* for *exported(public)* functions/methods:
206
-
- run `:GoTestsExp`
215
+
- run `:GoTestsExp`
207
216
208
-
You can also specify the template to use for generating the tests. See |gopher.nvim-config|
209
-
More details about templates can be found at: https://github.com/cweill/gotests
217
+
You can also specify the template to use for generating the tests.
218
+
See |gopher.nvim-config|.
219
+
More details about templates: https://github.com/cweill/gotests
210
220
211
221
If you prefer named tests, you can enable them in |gopher.nvim-config|.
212
222
···
229
239
This module provides a way to generate comments for Go code.
230
240
231
241
Usage ~
232
-
Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
242
+
243
+
Set cursor on line with function/method/struct/etc and
244
+
run `:GoCmt` to generate a comment.
233
245
234
246
235
247
vim:tw=78:ts=8:noet:ft=help:norl:
+3
-1
lua/gopher/comment.lua
+3
-1
lua/gopher/comment.lua
···
3
3
---@text
4
4
--- This module provides a way to generate comments for Go code.
5
5
---
6
-
---@usage Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment.
6
+
---@usage
7
+
--- Set cursor on line with function/method/struct/etc and
8
+
--- run `:GoCmt` to generate a comment.
7
9
8
10
local ts = require "gopher._utils.ts"
9
11
local log = require "gopher._utils.log"
+9
-3
lua/gopher/config.lua
+9
-3
lua/gopher/config.lua
···
30
30
timeout = 2000,
31
31
32
32
-- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
33
+
---@type number
33
34
installer_timeout = 999999,
34
35
35
36
-- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
···
46
47
},
47
48
---@class gopher.ConfigGotests
48
49
gotests = {
49
-
-- gotests doesn't have template named "default" so this plugin uses "default" to set the default template
50
+
-- a default template that gotess will use.
51
+
-- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
50
52
template = "default",
53
+
51
54
-- path to a directory containing custom test code templates
52
55
---@type string|nil
53
56
template_dir = nil,
54
-
-- switch table tests from using slice to map (with test name for the key)
57
+
58
+
-- use named tests(map with test name as key) in table tests(slice of structs by default)
55
59
named = false,
56
60
},
57
61
---@class gopher.ConfigGoTag
···
63
67
default_tag = "json",
64
68
65
69
-- default tag option added struct fields, set to nil to disable
70
+
-- e.g: `option = "json=omitempty,xml=omitempty`
66
71
---@type string|nil
67
72
option = nil,
68
73
},
69
74
iferr = {
70
-
-- choose a custom error message
75
+
-- choose a custom error message, nil to use default
76
+
-- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
71
77
---@type string|nil
72
78
message = nil,
73
79
},
+7
-6
lua/gopher/gotests.lua
+7
-6
lua/gopher/gotests.lua
···
3
3
---@text gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
4
4
---@usage
5
5
--- - Generate unit test for specific function/method:
6
-
--- 1. Place your cursor on the desired function/method.
7
-
--- 2. Run `:GoTestAdd`
6
+
--- 1. Place your cursor on the desired function/method.
7
+
--- 2. Run `:GoTestAdd`
8
8
---
9
9
--- - Generate unit tests for *all* functions/methods in current file:
10
-
--- - run `:GoTestsAll`
10
+
--- - run `:GoTestsAll`
11
11
---
12
12
--- - Generate unit tests *only* for *exported(public)* functions/methods:
13
-
--- - run `:GoTestsExp`
13
+
--- - run `:GoTestsExp`
14
14
---
15
-
--- You can also specify the template to use for generating the tests. See |gopher.nvim-config|
16
-
--- More details about templates can be found at: https://github.com/cweill/gotests
15
+
--- You can also specify the template to use for generating the tests.
16
+
--- See |gopher.nvim-config|.
17
+
--- More details about templates: https://github.com/cweill/gotests
17
18
---
18
19
--- If you prefer named tests, you can enable them in |gopher.nvim-config|.
19
20
+14
-13
lua/gopher/impl.lua
+14
-13
lua/gopher/impl.lua
···
3
3
---@text
4
4
--- Integration of `impl` tool to generate method stubs for interfaces.
5
5
---
6
-
---@usage 1. Automatically implement an interface for a struct:
7
-
--- - Place your cursor on the struct where you want to implement the interface.
8
-
--- - Run `:GoImpl io.Reader`
9
-
--- - This will automatically determine the receiver and implement the `io.Reader` interface.
6
+
---@usage
7
+
--- 1. Automatically implement an interface for a struct:
8
+
--- - Place your cursor on the struct where you want to implement the interface.
9
+
--- - Run `:GoImpl io.Reader`
10
+
--- - This will automatically determine the receiver and implement the `io.Reader` interface.
10
11
---
11
12
--- 2. Specify a custom receiver:
12
-
--- - Place your cursor on the struct
13
-
--- - Run `:GoImpl w io.Writer`, where:
14
-
--- - `w` is the receiver.
15
-
--- - `io.Writer` is the interface to implement.
13
+
--- - Place your cursor on the struct
14
+
--- - Run `:GoImpl w io.Writer`, where:
15
+
--- - `w` is the receiver.
16
+
--- - `io.Writer` is the interface to implement.
16
17
---
17
18
--- 3. Explicitly specify the receiver, struct, and interface:
18
-
--- - No need to place the cursor on the struct if all arguments are provided.
19
-
--- - Run `:GoImpl r RequestReader io.Reader`, where:
20
-
--- - `r` is the receiver.
21
-
--- - `RequestReader` is the struct.
22
-
--- - `io.Reader` is the interface to implement.
19
+
--- - No need to place the cursor on the struct if all arguments are provided.
20
+
--- - Run `:GoImpl r RequestReader io.Reader`, where:
21
+
--- - `r` is the receiver.
22
+
--- - `RequestReader` is the struct.
23
+
--- - `io.Reader` is the interface to implement.
23
24
---
24
25
--- Example:
25
26
--- >go
+5
-5
lua/gopher/init.lua
+5
-5
lua/gopher/init.lua
···
35
35
36
36
---@toc_entry Install dependencies
37
37
---@tag gopher.nvim-dependencies
38
-
---@text Gopher.nvim implements most of its features using third-party tools.
39
-
--- To install these tools, you can run `:GoInstallDeps` command
40
-
--- or call `require("gopher").install_deps()` if you want to use lua api.
41
-
--- By default dependencies will be installed asynchronously,
42
-
--- to install them synchronously pass `{sync = true}` as an argument.
38
+
---@text
39
+
--- Gopher.nvim implements most of its features using third-party tools. To
40
+
--- install plugin's dependencies, you can run:
41
+
--- `:GoInstallDeps` or `:GoInstallDepsSync`
42
+
--- or use `require("gopher").install_deps()` if you prefer lua api.
43
43
gopher.install_deps = require("gopher.installer").install_deps
44
44
45
45
gopher.impl = require("gopher.impl").impl