[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang

chore: update config docs

olexsmir.xyz 906e340b fabdcc5f

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