[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 internal commands 61 ---@type number 62 timeout = 2000, 63 64 --- whether to setup plugin commands or not 65 ---@type boolean 66 setup_commands = true, 67 68 -- user specified paths to binaries 69 ---@class gopher.ConfigCommand 70 commands = { 71 go = "go", 72 gomodifytags = "gomodifytags", 73 gotests = "gotests", 74 impl = "impl", 75 iferr = "iferr", 76 }, 77 ---@class gopher.ConfigGotests 78 gotests = { 79 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template 80 template = "default", 81 -- path to a directory containing custom test code templates 82 ---@type string|nil 83 template_dir = nil, 84 -- switch table tests from using slice to map (with test name for the key) 85 named = false, 86 }, 87 ---@class gopher.ConfigGoTag 88 gotag = { 89 ---@type gopher.ConfigGoTagTransform 90 transform = "snakecase", 91 92 -- default tags to add to struct fields 93 default_tag = "json", 94 }, 95 iferr = { 96 -- choose a custom error message 97 ---@type string|nil 98 message = nil, 99 }, 100 } 101< 102Class ~ 103{gopher.Config} 104 105 106============================================================================== 107------------------------------------------------------------------------------ 108 *gopher.nvim-struct-tags* 109struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields. 110Usage ~ 111 112How to add/remove tags to struct fields: 113 114------------------------------------------------------------------------------ 1152. Run `:GoTagAdd json` to add json tags to struct fields 1163. Run `:GoTagRm json` to remove json tags to struct fields 117 118NOTE: if you dont specify the tag it will use `json` as default 119 120Example: 121>go 122 // before 123 type User struct { 124 // ^ put your cursor here 125 // run `:GoTagAdd yaml` 126 ID int 127 Name string 128 } 129 130 // after 131 type User struct { 132 ID int `yaml:id` 133 Name string `yaml:name` 134 } 135< 136------------------------------------------------------------------------------ 137 *struct_tags.add()* 138 `struct_tags.add`({...}) 139tags to a struct under the cursor 140Parameters ~ 141{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] 142 143------------------------------------------------------------------------------ 144 *struct_tags.remove()* 145 `struct_tags.remove`({...}) 146tags from a struct under the cursor 147Parameters ~ 148{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] 149 150------------------------------------------------------------------------------ 151 *struct_tags.clear()* 152 `struct_tags.clear`() 153all tags from a struct under the cursor 154 155 156============================================================================== 157------------------------------------------------------------------------------ 158 *gopher.nvim-impl* 159impl is utilizing the `impl` tool to generate method stubs for interfaces. 160Usage ~ 161 1621. 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 1672. 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 1733. 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 180Example: 181>go 182 type BytesReader struct{} 183 // ^ put your cursor here 184 // run `:GoImpl b io.Reader` 185 186 // this is what you will get 187 func (b *BytesReader) Read(p []byte) (n int, err error) { 188 panic("not implemented") // TODO: Implement 189 } 190< 191 192============================================================================== 193------------------------------------------------------------------------------ 194 *gopher.nvim-gotests* 195gotests is utilizing the `gotests` tool to generate unit tests boilerplate. 196Usage ~ 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 208You can also specify the template to use for generating the tests. See |gopher.nvim-config| 209More details about templates can be found at: https://github.com/cweill/gotests 210 211------------------------------------------------------------------------------ 212 *gopher.nvim-gotests-named* 213 214You can enable named tests in the config if you prefer using named tests. 215See |gopher.nvim-config|. 216 217 218============================================================================== 219------------------------------------------------------------------------------ 220 *gopher.nvim-iferr* 221If you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check. 222Usage ~ 223Execute `:GoIfErr` near any `err` variable to insert the check 224 225 226============================================================================== 227------------------------------------------------------------------------------ 228 *gopher.nvim-comments* 229Usage ~ 230Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line. 231This module provides a way to generate comments for Go code. 232 233 234 vim:tw=78:ts=8:noet:ft=help:norl: