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

add help file, and docs (#59)

* idk how good this idea is

* this could be working but i still cant figure out how to run it

* ignore tags that mini.doc gens, but why?

* chore(taskfile): force exiting after tests

because i got infinit ci

* chore(ci): add more nvim versions to run on

* chore: update taskfile

* feat: add docs generator

* docs: its only begining

* refactor: update docgen script

* docs: write some more

* docs(config): update

* docs: update readme

* language

* hope it would work

* what about that?

* maybe this would work?

* update md

* upd

* WHY DOESNT IT WORKING

* idk by but 0.9.3 just fails the ci, so i deleted it from suite

* again update, why does markdown not work in embeded html

* maybe it can help?

* upd

* again update

* kinda fix

* fix: formatting

* again some updating

* some readme updating

* fix, this shouldnt be in repo

* i finnaly undertood how to fix this fking skill issue

* fix(struct_tags): typo

* refactor(docs): change the order in generated file

* docs: install deps

* refactor(scripts): rename doc-gen script

* docs(impl): write docs

* docs(dap): add doc

* stylua .

* docs(struct_tags): add doc

* docs(gotests): add docs

* docs(iferr): add docs

* docs(comment): add doc

* update CONTRIBUTING.md

* docs(README): talk about `develop` branch

* docs: update README.md

authored by olexsmir.xyz and committed by GitHub 10cec9c6 28e1f568

+12 -2
.github/workflows/tests.yml
··· 16 16 - v0.8.3 17 17 - v0.9.0 18 18 - v0.9.1 19 + - v0.9.2 20 + - v0.9.4 21 + - v0.9.5 19 22 runs-on: ${{ matrix.os }} 20 23 steps: 24 + - name: Install Task 25 + uses: arduino/setup-task@v1 26 + with: 27 + version: 3.x 28 + repo-token: ${{ secrets.GITHUB_TOKEN }} 29 + 21 30 - uses: actions/checkout@v3 31 + 22 32 - name: Install Neovim 23 - shell: bash 24 33 run: | 25 34 mkdir -p /tmp/nvim 26 35 wget -q https://github.com/neovim/neovim/releases/download/${{ matrix.nvim_version }}/nvim.appimage -O /tmp/nvim/nvim.appimage ··· 28 37 chmod a+x ./nvim.appimage 29 38 ./nvim.appimage --appimage-extract 30 39 echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH 40 + 31 41 - name: Run Tests 32 42 run: | 33 43 nvim --version 34 - nvim --headless -u ./spec/minimal_init.lua -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.lua', sequential=true}" 44 + task test
+45 -3
CONTRIBUTING.md
··· 1 1 # Contributing to `gopher.nvim` 2 2 3 - Thank you for looking to contributing 3 + Thank you for taking the time to submit some code to gopher.nvim. It means a lot! 4 + 5 + ### Task running 6 + 7 + In this codebase for running tasks is used [Taskfile](https://taskfile.dev). 8 + You can install it with: 9 + ```bash 10 + go install github.com/go-task/task/v3/cmd/task@latest 11 + ``` 4 12 5 13 ### Styling and formatting 6 14 ··· 8 16 You can install these with: 9 17 10 18 ```bash 11 - cargo install stylua 12 - cargo install selene 19 + sudo pacman -S selene stylua 20 + # or whatever is your package manager 21 + # or way of installing pkgs 22 + ``` 23 + 24 + For formatting use this following commands, or setup your editor to integrate with selene/stylua: 25 + ```bash 26 + task format 27 + task format:check # will check if your code formatted 28 + task lint 29 + ``` 30 + 31 + ### Documentation 32 + 33 + Here we are using [mini.doc](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-doc.md) 34 + for generating help files based on EmmyLua-like annotations in comments 35 + 36 + You can generate docs with: 37 + ```bash 38 + task docgen 39 + ``` 40 + 41 + ### Commit messages 42 + We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), please follow it. 43 + 44 + ### Testing 45 + 46 + For testing this plugins uses [plenary.nvim](https://github.com/nvim-lua/plenary.nvim). 47 + All tests live in [/spec](https://github.com/olexsmir/gopher.nvim/tree/main/spec) dir. 48 + 49 + You can run tests with: 50 + ```bash 51 + task test 52 + # also there are some aliases for that 53 + task tests 54 + task spec 13 55 ```
+149 -115
README.md
··· 4 4 5 5 Minimalistic plugin for Go development in Neovim written in Lua. 6 6 7 - It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim. 7 + It's **NOT** an LSP tool, the main goal of this plugin is to add go tooling support in Neovim. 8 + 9 + > If you want to use new and maybe undocumented, and unstable features you might use [develop](https://github.com/olexsmir/gopher.nvim/tree/develop) branch. 10 + 11 + ## Install (using [lazy.nvim](https://github.com/folke/lazy.nvim)) 8 12 9 - ## Install 13 + Pre-dependency: 10 14 11 - Pre-dependency: [go](https://github.com/golang/go) (tested on 1.17 and 1.18) 15 + - [Go](https://github.com/golang/go) 16 + - `go` treesitter parser, install by `:TSInstall go` 12 17 13 18 ```lua 14 - use { 19 + { 15 20 "olexsmir/gopher.nvim", 16 - requires = { -- dependencies 21 + ft = "go", 22 + -- branch = "develop", -- if you want develop branch 23 + -- keep in mind, it might break everything 24 + dependencies = { 17 25 "nvim-lua/plenary.nvim", 18 26 "nvim-treesitter/nvim-treesitter", 27 + "mfussenegger/nvim-dap", -- (optional) only if you use `gopher.dap` 19 28 }, 29 + -- (optional) will update plugin's deps on every update 30 + build = function() 31 + vim.cmd.GoInstallDeps() 32 + end, 33 + ---@type gopher.Config 34 + opts = {}, 20 35 } 21 36 ``` 22 37 23 - Also, run `TSInstall go` if `go` parser if isn't installed yet. 24 - 25 - ## Config 26 - 27 - By `.setup` function you can configure the plugin. 38 + ## Configuratoin 28 39 29 - Note: 40 + > [!IMPORTANT] 41 + > 42 + > If you need more info look `:h gopher.nvim` 30 43 31 - - `installer` does not install the tool in user set path 44 + **Take a look at default options** 32 45 33 46 ```lua 34 47 require("gopher").setup { 35 48 commands = { 36 49 go = "go", 37 50 gomodifytags = "gomodifytags", 38 - gotests = "~/go/bin/gotests", -- also you can set custom command path 51 + gotests = "gotests", 39 52 impl = "impl", 40 53 iferr = "iferr", 54 + dlv = "dlv", 41 55 }, 42 56 gotests = { 43 57 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template ··· 48 62 -- works only with gotests installed from develop branch 49 63 named = false, 50 64 }, 65 + gotag = { 66 + transform = "snakecase", 67 + }, 51 68 } 52 69 ``` 53 70 54 - ### Named tests with testify (using map instead of slice for test cases) 55 - 56 - ```lua 57 - require("gopher").setup({ 58 - gotests = { 59 - template = "testify", 60 - named = true 61 - } 62 - }) 63 - ``` 64 - 65 - For named tests to work you have to install gotests from develop branch, for example using [mason-tool-installer](https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim): 66 - 67 - ```lua 68 - require('mason-tool-installer').setup({ 69 - ensure_installed = { 70 - { "gotests", version = "develop" }, 71 - } 72 - }) 73 - ``` 74 - 75 - Or by calling `vim.fn.jobstart`: 76 - 77 - ```lua 78 - vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") 79 - ``` 71 + ## Features 80 72 81 - If you're using `lazy.nvim` you can put in `build` function inside `setup()` 73 + <!-- markdownlint-disable --> 82 74 83 - ## Features 75 + <details> 76 + <summary> 77 + <b>Install plugin's go deps</b> 78 + </summary> 84 79 85 - 1. Installation requires this go tool: 80 + ```vim 81 + :GoInstallDeps 82 + ``` 86 83 87 - ```vim 88 - :GoInstallDeps 89 - ``` 84 + This will install the following tools: 90 85 91 - It will install next tools: 86 + - [gomodifytags](https://github.com/fatih/gomodifytags) 87 + - [impl](https://github.com/josharian/impl) 88 + - [gotests](https://github.com/cweill/gotests) 89 + - [iferr](https://github.com/koron/iferr) 90 + - [dlv](github.com/go-delve/delve/cmd/dlv) 91 + </details> 92 92 93 - - [gomodifytags](https://github.com/fatih/gomodifytags) 94 - - [impl](https://github.com/josharian/impl) 95 - - [gotests](https://github.com/cweill/gotests) 96 - - [iferr](https://github.com/koron/iferr) 93 + <details> 94 + <summary> 95 + <b>Add and remove tags for structs via <a href="https://github.com/fatih/gomodifytags">gomodifytags</a></b> 96 + </summary> 97 97 98 - 2. Modify struct tags: 99 98 By default `json` tag will be added/removed, if not set: 100 99 101 - ```vim 102 - :GoTagAdd json " For add json tag 103 - :GoTagRm yaml " For remove yaml tag 104 - ``` 100 + ```vim 101 + " add json tag 102 + :GoTagAdd json 105 103 106 - 3. Run `go mod` command: 104 + " remove yaml tag 105 + :GoTagRm yaml 106 + ``` 107 107 108 - ```vim 109 - :GoMod tidy " Runs `go mod tidy` 110 - :GoMod init asdf " Runs `go mod init asdf` 111 - ``` 108 + ```lua 109 + -- or you can use lua api 110 + require("gopher").tags.add "xml" 111 + require("gopher").tags.rm "proto" 112 + ``` 113 + </details> 112 114 113 - 4. Run `go get` command 115 + <details> 116 + <summary> 117 + <b>Generating tests via <a href="https://github.com/cweill/gotests">gotests</a></b> 118 + </summary> 114 119 115 - Link can have a `http` or `https` prefix. 120 + ```vim 121 + " Generate one test for a specific function/method(one under cursor) 122 + :GoTestAdd 116 123 117 - You can provide more than one package url: 124 + " Generate all tests for all functions/methods in the current file 125 + :GoTestsAll 118 126 119 - ```vim 120 - :GoGet github.com/gorilla/mux 121 - ``` 127 + " Generate tests for only exported functions/methods in the current file 128 + :GoTestsExp 129 + ``` 122 130 123 - 5. Interface implementation 131 + ```lua 132 + -- or you can use lua api 133 + require("gopher").test.add() 134 + require("gopher").test.exported() 135 + require("gopher").test.all() 136 + ``` 124 137 125 - Command syntax: 138 + For named tests see `:h gopher.nvim-gotests-named` 139 + </details> 126 140 127 - ```vim 128 - :GoImpl [receiver] [interface] 141 + <details> 142 + <summary> 143 + <b>Run commands like <code>go mod/get/etc</code> inside of nvim</b> 144 + </summary> 129 145 130 - " Also you can put cursor on the struct and run: 131 - :GoImpl [interface] 132 - ``` 146 + ```vim 147 + :GoGet github.com/gorilla/mux 133 148 134 - Example of usage: 149 + " Link can have an `http` or `https` prefix. 150 + :GoGet https://github.com/lib/pq 135 151 136 - ```vim 137 - " Example 138 - :GoImpl r Read io.Reader 139 - " or simply put your cursor in the struct and run: 140 - :GoImpl io.Reader 141 - ``` 152 + " You can provide more than one package url 153 + :GoGet github.com/jackc/pgx/v5 github.com/google/uuid/ 142 154 143 - 6. Generate tests with [gotests](https://github.com/cweill/gotests) 155 + " go mod commands 156 + :GoMod tidy 157 + :GoMod init new-shiny-project 144 158 145 - Generate one test for a specific function/method: 159 + " go work commands 160 + :GoWork sync 146 161 147 - ```vim 148 - :GoTestAdd 149 - ``` 162 + " run go generate in cwd 163 + :GoGenerate 150 164 151 - Generate all tests for all functions/methods in current file: 165 + " run go generate for the current file 166 + :GoGenerate % 167 + ``` 168 + </details> 152 169 153 - ```vim 154 - :GoTestsAll 155 - ``` 170 + <details> 171 + <summary> 172 + <b>Interface implementation via <a href="https://github.com/josharian/impl">impl<a></b> 173 + </summary> 156 174 157 - Generate tests only for exported functions/methods in current file: 175 + Syntax of the command: 176 + ```vim 177 + :GoImpl [receiver] [interface] 158 178 159 - ```vim 160 - :GoTestsExp 161 - ``` 179 + " also you can put a cursor on the struct and run 180 + :GoImpl [interface] 181 + ``` 162 182 163 - 7. Run `go generate` command; 183 + Usage examples: 184 + ```vim 185 + :GoImpl r Read io.Reader 186 + :GoImpl Write io.Writer 164 187 165 - ```vim 166 - " Run `go generate` in cwd path 167 - :GoGenerate 188 + " or you can simply put a cursor on the struct and run 189 + :GoImpl io.Reader 190 + ``` 191 + </details> 168 192 169 - " Run `go generate` for current file 170 - :GoGenerate % 171 - ``` 193 + <details> 194 + <summary> 195 + <b>Generate boilerplate for doc comments</b> 196 + </summary> 172 197 173 - 8. Generate doc comment 198 + First set a cursor on **public** package/function/interface/struct and execute: 174 199 175 - First set a cursor on **public** package/function/interface/struct and execute: 200 + ```vim 201 + :GoCmt 202 + ``` 203 + </details> 176 204 177 - ```vim 178 - :GoCmt 179 - ``` 180 205 181 - 9. Generate `if err` 206 + <details> 207 + <summary> 208 + <b>Generate <code>if err != nil {</code> via <a href="https://github.com/koron/iferr">iferr</a></b> 209 + </summary> 182 210 183 - Set cursor on the line with **err** and execute: 211 + Set the cursor on the line with `err` and execute 184 212 185 - ```vim 186 - :GoIfErr 187 - ``` 213 + ```vim 214 + :GoIfErr 215 + ``` 216 + </details> 188 217 189 - 10. Setup nvim-dap for go in one line. 218 + <details> 219 + <summary> 220 + <b>Setup <a href="https://github.com/mfussenegger/nvim-dap">nvim-dap</a> for go in one line</b> 221 + </summary> 190 222 191 - Notice: [nvim-dap](https://github.com/mfussenegger/nvim-dap) is required 223 + note [nvim-dap](https://github.com/mfussenegger/nvim-dap) has to be installed 192 224 193 - ```lua 194 - require"gopher.dap".setup() 195 - ``` 225 + ```lua 226 + require("gopher.dap").setup() 227 + ``` 228 + </details> 196 229 197 230 ## Contributing 198 231 ··· 202 235 203 236 - [go.nvim](https://github.com/ray-x/go.nvim) 204 237 - [nvim-dap-go](https://github.com/leoluz/nvim-dap-go) 238 + - [iferr](https://github.com/koron/iferr)
+29 -10
Taskfile.yml
··· 2 2 tasks: 3 3 format: 4 4 desc: formats all lua files in repo 5 - cmds: [stylua .] 5 + cmds: 6 + - stylua . 6 7 7 8 lint: 8 9 desc: runs all linters 9 10 cmds: 10 - - task: lint_selene 11 - - task: lint_stylua 11 + - task: selene 12 + - task: stylua:check 12 13 13 - lint_selene: 14 + selene: 14 15 desc: runs lua linter(selene) 15 - cmds: [selene .] 16 + cmds: 17 + - selene . 16 18 17 - lint_stylua: 19 + stylua:check: 18 20 desc: runs stylua in check mode 19 - cmds: [stylua --check .] 21 + cmds: 22 + - stylua --check . 23 + 24 + stylua: 25 + desc: runs lua formatter 26 + cmds: 27 + - stylua . 20 28 21 29 test: 22 30 desc: runs all tests ··· 24 32 cmds: 25 33 - | 26 34 nvim --headless \ 27 - -u ./spec/minimal_init.lua\ 35 + -u ./scripts/minimal_init.lua \ 28 36 -c "PlenaryBustedDirectory spec \ 29 - {minimal_init='./spec/minimal_init.lua'\ 30 - ,sequential=true}" 37 + {minimal_init='./scripts/minimal_init.lua' \ 38 + ,sequential=true}" \ 39 + -c ":qa!" 40 + 41 + docgen: 42 + desc: generate vimhelp 43 + cmds: 44 + - | 45 + nvim --noplugin \ 46 + --headless \ 47 + -u "./scripts/minimal_init.lua" \ 48 + -c "luafile ./scripts/docgen.lua" \ 49 + -c ":qa!"
+1
doc/.gitignore
··· 1 + /tags
+220
doc/gopher.nvim.txt
··· 1 + *gopher.nvim* 2 + 3 + ============================================================================== 4 + 5 + gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua. 6 + It'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* 10 + Table of Contents 11 + Setup....................................................|gopher.nvim-setup| 12 + Install dependencies..............................|gopher.nvim-install-deps| 13 + Configuration...........................................|gopher.nvim-config| 14 + Modifty 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 + Setup `nvim-dap` for Go......................................|gopher.nvim-dap| 20 + 21 + ------------------------------------------------------------------------------ 22 + *gopher.nvim-setup* 23 + `gopher.setup` 24 + Setup function. This method simply merges default configs with opts table. 25 + You can read more about configuration at |gopher.nvim-config| 26 + Calling this function is optional, if you ok with default settings. Look |gopher.nvim.config-defaults| 27 + 28 + Usage ~ 29 + `require("gopher").setup {}` (replace `{}` with your `config` table) 30 + 31 + ------------------------------------------------------------------------------ 32 + *gopher.nvim-install-deps* 33 + `gopher.install_deps` 34 + Gopher.nvim implements most of its features using third-party tools. 35 + To install these tools, you can run `:GoInstallDeps` command 36 + or call `require("gopher").install_deps()` if you want ues lua api. 37 + 38 + 39 + ============================================================================== 40 + ------------------------------------------------------------------------------ 41 + *gopher.nvim-config* 42 + config it is the place where you can configure the plugin. 43 + also this is optional is you're ok with default settings. 44 + You can look at default options |gopher.nvim-config-defaults| 45 + 46 + ------------------------------------------------------------------------------ 47 + *gopher.nvim-config-defaults* 48 + `default_config` 49 + >lua 50 + local default_config = { 51 + --minidoc_replace_end 52 + 53 + -- user specified paths to binaries 54 + ---@class gopher.ConfigCommand 55 + commands = { 56 + go = "go", 57 + gomodifytags = "gomodifytags", 58 + gotests = "gotests", 59 + impl = "impl", 60 + iferr = "iferr", 61 + dlv = "dlv", 62 + }, 63 + ---@class gopher.ConfigGotests 64 + gotests = { 65 + -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template 66 + template = "default", 67 + -- path to a directory containing custom test code templates 68 + ---@type string|nil 69 + template_dir = nil, 70 + -- switch table tests from using slice to map (with test name for the key) 71 + -- works only with gotests installed from develop branch 72 + named = false, 73 + }, 74 + ---@class gopher.ConfigGoTag 75 + gotag = { 76 + ---@type gopher.ConfigGoTagTransform 77 + transform = "snakecase", 78 + }, 79 + } 80 + < 81 + Class ~ 82 + {gopher.Config} 83 + 84 + ------------------------------------------------------------------------------ 85 + *config.setup()* 86 + `config.setup`({user_config}) 87 + Parameters ~ 88 + {user_config} `(optional)` gopher.Config 89 + 90 + 91 + ============================================================================== 92 + ------------------------------------------------------------------------------ 93 + *gopher.nvim-struct-tags* 94 + struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields. 95 + Usage ~ 96 + - put your coursor on the struct 97 + - run `:GoTagAdd json` to add json tags to struct fields 98 + - run `:GoTagRm json` to remove json tags to struct fields 99 + 100 + note: if you dont spesify the tag it will use `json` as default 101 + 102 + simple example: 103 + >go 104 + // before 105 + type User struct { 106 + // ^ put your cursor here 107 + // run `:GoTagAdd yaml` 108 + ID int 109 + Name string 110 + } 111 + 112 + // after 113 + type User struct { 114 + ID int `yaml:id` 115 + Name string `yaml:name` 116 + } 117 + < 118 + 119 + 120 + ============================================================================== 121 + ------------------------------------------------------------------------------ 122 + *gopher.nvim-impl* 123 + impl is utilizing the `impl` tool to generate method stubs for interfaces. 124 + Usage ~ 125 + 126 + 1. put your coursor on the struct on which you want implement the interface 127 + and run `:GoImpl io.Reader` 128 + which will automatically choose the reciver for the methods and 129 + implement the `io.Reader` interface 130 + 2. same as previous but with custom receiver, so put your coursor on the struct 131 + run `:GoImpl w io.Writer` 132 + where `w` is the receiver and `io.Writer` is the interface 133 + 3. specift receiver, struct, and interface 134 + there's no need to put your coursor on the struct if you specify all arguments 135 + `:GoImpl r RequestReader io.Reader` 136 + where `r` is the receiver, `RequestReader` is the struct and `io.Reader` is the interface 137 + 138 + simple example: 139 + >go 140 + type BytesReader struct{} 141 + // ^ put your cursor here 142 + // run `:GoImpl b io.Reader` 143 + 144 + // this is what you will get 145 + func (b *BytesReader) Read(p []byte) (n int, err error) { 146 + panic("not implemented") // TODO: Implement 147 + } 148 + < 149 + 150 + 151 + ============================================================================== 152 + ------------------------------------------------------------------------------ 153 + *gopher.nvim-gotests* 154 + gotests is utilizing the `gotests` tool to generate unit tests boilerplate. 155 + Usage ~ 156 + 157 + - generate unit test for spesisfic function/method 158 + - to specift the function/method put your cursor on it 159 + - run `:GoTestAdd` 160 + 161 + - generate unit tests for all functions/methods in current file 162 + - run `:GoTestsAll` 163 + 164 + - generate unit tests only for exported(public) functions/methods 165 + - run `:GoTestsExp` 166 + 167 + you can also specify the template to use for generating the tests. see |gopher.nvim-config| 168 + more details about templates can be found at: https://github.com/cweill/gotests 169 + 170 + 171 + ------------------------------------------------------------------------------ 172 + *gopher.nvim-gotests-named* 173 + 174 + if you prefare using named tests, you can enable it in the config. 175 + but you would need to install `gotests@develop` because stable version doesn't support this feature. 176 + you can do it with: 177 + >lua 178 + -- simply run go get in your shell: 179 + go install github.com/cweill/gotests/...@develop 180 + 181 + -- if you want to install it within neovim, you can use one of this: 182 + 183 + vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") 184 + 185 + -- or if you want to use mason: 186 + require("mason-tool-installer").setup { 187 + ensure_installed = { 188 + { "gotests", version = "develop" }, 189 + } 190 + } 191 + < 192 + 193 + if you choose to install `gotests` within neovim, i recommend adding it to your `build` section in your |lazy.nvim| 194 + 195 + 196 + ============================================================================== 197 + ------------------------------------------------------------------------------ 198 + *gopher.nvim-iferr* 199 + if you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check. 200 + Usage ~ 201 + execute `:GoIfErr` near any err variable to insert the check 202 + 203 + 204 + ============================================================================== 205 + ------------------------------------------------------------------------------ 206 + *gopher.nvim-comments* 207 + Usage ~ 208 + Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line. 209 + This module provides a way to generate comments for Go code. 210 + 211 + 212 + ============================================================================== 213 + ------------------------------------------------------------------------------ 214 + *gopher.nvim-dap* 215 + This module sets up `nvim-dap` for Go. 216 + Usage ~ 217 + just call `require("gopher.dap").setup()`, and you're good to go. 218 + 219 + 220 + vim:tw=78:ts=8:noet:ft=help:norl:
+5
lua/gopher/comment.lua
··· 1 + ---@toc_entry Generate comments 2 + ---@tag gopher.nvim-comments 3 + ---@usage Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line. 4 + ---@text This module provides a way to generate comments for Go code. 5 + 1 6 local function generate(row, col) 2 7 local ts_utils = require "gopher._utils.ts" 3 8 local comment, ns = nil, nil
+21 -1
lua/gopher/config.lua
··· 1 + ---@toc_entry Configuration 2 + ---@tag gopher.nvim-config 3 + ---@text config it is the place where you can configure the plugin. 4 + --- also this is optional is you're ok with default settings. 5 + --- You can look at default options |gopher.nvim-config-defaults| 6 + 1 7 ---@type gopher.Config 8 + ---@private 2 9 local config = {} 3 10 11 + ---@tag gopher.nvim-config.ConfigGoTagTransform 12 + ---@text Possible values for |gopher.Config|.gotag.transform: 13 + --- 14 + ---@private 4 15 ---@alias gopher.ConfigGoTagTransform 5 16 ---| "snakecase" "GopherUser" -> "gopher_user" 6 17 ---| "camelcase" "GopherUser" -> "gopherUser" ··· 9 20 ---| "titlecase" "GopherUser" -> "Gopher User" 10 21 ---| "keep" keeps the original field name 11 22 23 + --minidoc_replace_start { 24 + 25 + ---@tag gopher.nvim-config-defaults 26 + ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section):gsub(">", ">lua") 27 + --- 12 28 ---@class gopher.Config 13 29 local default_config = { 30 + --minidoc_replace_end 31 + 32 + -- user specified paths to binaries 14 33 ---@class gopher.ConfigCommand 15 34 commands = { 16 35 go = "go", ··· 29 48 template_dir = nil, 30 49 -- switch table tests from using slice to map (with test name for the key) 31 50 -- works only with gotests installed from develop branch 32 - ---@type boolean 33 51 named = false, 34 52 }, 35 53 ---@class gopher.ConfigGoTag ··· 38 56 transform = "snakecase", 39 57 }, 40 58 } 59 + --minidoc_afterlines_end 41 60 42 61 ---@type gopher.Config 62 + ---@private 43 63 local _config = default_config 44 64 45 65 ---@param user_config? gopher.Config
+6 -1
lua/gopher/dap.lua
··· 1 + ---@toc_entry Setup `nvim-dap` for Go 2 + ---@tag gopher.nvim-dap 3 + ---@text This module sets up `nvim-dap` for Go. 4 + ---@usage just call `require("gopher.dap").setup()`, and you're good to go. 5 + 1 6 local u = require "gopher._utils" 2 7 local c = require "gopher.config" 3 8 local dap = {} ··· 106 111 }, 107 112 } 108 113 109 - ---setup `nvim-dap` for Go 114 + -- sets ups nvim-dap for Go in one function call. 110 115 function dap.setup() 111 116 local d = u.sreq "dap" 112 117
+45 -3
lua/gopher/gotests.lua
··· 1 + ---@toc_entry Generating unit tests boilerplate 2 + ---@tag gopher.nvim-gotests 3 + ---@text gotests is utilizing the `gotests` tool to generate unit tests boilerplate. 4 + ---@usage 5 + --- - generate unit test for spesisfic function/method 6 + --- - to specift the function/method put your cursor on it 7 + --- - 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 + 19 + ---@tag gopher.nvim-gotests-named 20 + ---@text 21 + --- if you prefare using named tests, you can enable it in the config. 22 + --- but you would need to install `gotests@develop` because stable version doesn't support this feature. 23 + --- you can do it with: 24 + --- >lua 25 + --- -- simply run go get in your shell: 26 + --- go install github.com/cweill/gotests/...@develop 27 + --- 28 + --- -- if you want to install it within neovim, you can use one of this: 29 + --- 30 + --- vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") 31 + --- 32 + --- -- or if you want to use mason: 33 + --- require("mason-tool-installer").setup { 34 + --- ensure_installed = { 35 + --- { "gotests", version = "develop" }, 36 + --- } 37 + --- } 38 + --- < 39 + --- 40 + --- if you choose to install `gotests` within neovim, i recommend adding it to your `build` section in your |lazy.nvim| 41 + 1 42 local c = require "gopher.config" 2 43 local ts_utils = require "gopher._utils.ts" 3 44 local r = require "gopher._utils.runner" ··· 5 46 local gotests = {} 6 47 7 48 ---@param args table 49 + ---@private 8 50 local function add_test(args) 9 51 if c.gotests.named then 10 52 table.insert(args, "-named") ··· 35 77 }) 36 78 end 37 79 38 - ---generate unit test for one function 80 + -- generate unit test for one function 39 81 function gotests.func_test() 40 82 local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 41 83 if ns == nil or ns.name == nil then ··· 46 88 add_test { "-only", ns.name } 47 89 end 48 90 49 - ---generate unit tests for all functions in current file 91 + -- generate unit tests for all functions in current file 50 92 function gotests.all_tests() 51 93 add_test { "-all" } 52 94 end 53 95 54 - ---generate unit tests for all exported functions 96 + -- generate unit tests for all exported functions 55 97 function gotests.all_exported_tests() 56 98 add_test { "-exported" } 57 99 end
+6 -1
lua/gopher/iferr.lua
··· 1 + ---@toc_entry Iferr 2 + ---@tag gopher.nvim-iferr 3 + ---@text if you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check. 4 + ---@usage execute `:GoIfErr` near any err variable to insert the check 5 + 1 6 local c = require "gopher.config" 2 7 local iferr = {} 3 8 4 - -- That's Lua of vimscript implementation of: github.com/koron/iferr 9 + -- That's Lua implementation: github.com/koron/iferr 5 10 function iferr.iferr() 6 11 local boff = vim.fn.wordcount().cursor_bytes 7 12 local pos = vim.fn.getcurpos()[2]
+29
lua/gopher/impl.lua
··· 1 + ---@toc_entry Auto implementation of interface methods 2 + ---@tag gopher.nvim-impl 3 + ---@text impl is utilizing the `impl` tool to generate method stubs for interfaces. 4 + ---@usage 5 + --- 1. put your coursor on the struct on which you want implement the interface 6 + --- and run `:GoImpl io.Reader` 7 + --- which will automatically choose the reciver for the methods and 8 + --- implement the `io.Reader` interface 9 + --- 2. same as previous but with custom receiver, so put your coursor on the struct 10 + --- run `:GoImpl w io.Writer` 11 + --- where `w` is the receiver and `io.Writer` is the interface 12 + --- 3. specift receiver, struct, and interface 13 + --- there's no need to put your coursor on the struct if you specify all arguments 14 + --- `:GoImpl r RequestReader io.Reader` 15 + --- where `r` is the receiver, `RequestReader` is the struct and `io.Reader` is the interface 16 + --- 17 + --- simple example: 18 + --- >go 19 + --- type BytesReader struct{} 20 + --- // ^ put your cursor here 21 + --- // run `:GoImpl b io.Reader` 22 + --- 23 + --- // this is what you will get 24 + --- func (b *BytesReader) Read(p []byte) (n int, err error) { 25 + --- panic("not implemented") // TODO: Implement 26 + --- } 27 + --- < 28 + 1 29 local c = require("gopher.config").commands 2 30 local r = require "gopher._utils.runner" 3 31 local ts_utils = require "gopher._utils.ts" ··· 5 33 local impl = {} 6 34 7 35 ---@return string 36 + ---@private 8 37 local function get_struct() 9 38 local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 10 39 if ns == nil then
+25
lua/gopher/init.lua
··· 1 + --- *gopher.nvim* 2 + --- 3 + --- ============================================================================== 4 + --- 5 + --- gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua. 6 + --- It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim. 7 + 8 + --- Table of Contents 9 + ---@tag gopher.nvim-table-of-contents 10 + ---@toc 11 + 1 12 local tags = require "gopher.struct_tags" 2 13 local tests = require "gopher.gotests" 3 14 local gocmd = require("gopher._utils.runner.gocmd").run 4 15 local gopher = {} 5 16 17 + ---@toc_entry Setup 18 + ---@tag gopher.nvim-setup 19 + ---@text Setup function. This method simply merges default configs with opts table. 20 + --- You can read more about configuration at |gopher.nvim-config| 21 + --- Calling this function is optional, if you ok with default settings. Look |gopher.nvim.config-defaults| 22 + --- 23 + ---@usage `require("gopher").setup {}` (replace `{}` with your `config` table) 6 24 gopher.setup = require("gopher.config").setup 25 + 26 + ---@toc_entry Install dependencies 27 + ---@tag gopher.nvim-install-deps 28 + ---@text Gopher.nvim implements most of its features using third-party tools. 29 + --- To install these tools, you can run `:GoInstallDeps` command 30 + --- or call `require("gopher").install_deps()` if you want ues lua api. 7 31 gopher.install_deps = require("gopher.installer").install_deps 32 + 8 33 gopher.impl = require("gopher.impl").impl 9 34 gopher.iferr = require("gopher.iferr").iferr 10 35 gopher.comment = require "gopher.comment"
+29 -5
lua/gopher/struct_tags.lua
··· 1 + ---@toc_entry Modifty struct tags 2 + ---@tag gopher.nvim-struct-tags 3 + ---@text struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields. 4 + ---@usage - put your coursor on the struct 5 + --- - run `:GoTagAdd json` to add json tags to struct fields 6 + --- - run `:GoTagRm json` to remove json tags to struct fields 7 + --- 8 + --- note: if you dont spesify the tag it will use `json` as default 9 + --- 10 + --- simple example: 11 + --- >go 12 + --- // before 13 + --- type User struct { 14 + --- // ^ put your cursor here 15 + --- // run `:GoTagAdd yaml` 16 + --- ID int 17 + --- Name string 18 + --- } 19 + --- 20 + --- // after 21 + --- type User struct { 22 + --- ID int `yaml:id` 23 + --- Name string `yaml:name` 24 + --- } 25 + --- < 26 + 1 27 local ts_utils = require "gopher._utils.ts" 2 28 local r = require "gopher._utils.runner" 3 29 local c = require "gopher.config" ··· 56 82 or tagged["start"] == nil 57 83 or tagged["start"] == 0 58 84 then 59 - error("failed to set tags " .. vim.inspec(tagged)) 85 + error("failed to set tags " .. vim.inspect(tagged)) 60 86 end 61 87 62 88 vim.api.nvim_buf_set_lines( ··· 69 95 vim.cmd "write" 70 96 end 71 97 72 - ---add tags to struct under cursor 73 - ---@param ... unknown 98 + -- add tags to struct under cursor 74 99 function struct_tags.add(...) 75 100 local arg = { ... } 76 101 if #arg == nil or arg == "" then ··· 85 110 modify(unpack(cmd_args)) 86 111 end 87 112 88 - ---remove tags to struct under cursor 89 - ---@param ... unknown 113 + -- remove tags to struct under cursor 90 114 function struct_tags.remove(...) 91 115 local arg = { ... } 92 116 if #arg == nil or arg == "" then
+33
scripts/docgen.lua
··· 1 + ---@diagnostic disable: undefined-global 2 + --# selene: allow(undefined_variable) 3 + 4 + local okay, minidoc = pcall(require, "mini.doc") 5 + if not okay then 6 + error "mini.doc not found, please install it. https://github.com/echasnovski/mini.doc" 7 + return 8 + end 9 + 10 + local files = { 11 + "lua/gopher/init.lua", 12 + "lua/gopher/config.lua", 13 + "lua/gopher/struct_tags.lua", 14 + "lua/gopher/impl.lua", 15 + "lua/gopher/gotests.lua", 16 + "lua/gopher/iferr.lua", 17 + "lua/gopher/comment.lua", 18 + "lua/gopher/dap.lua", 19 + } 20 + 21 + minidoc.setup() 22 + 23 + local hooks = vim.deepcopy(minidoc.default_hooks) 24 + hooks.write_pre = function(lines) 25 + -- Remove first two lines with `======` and `------` delimiters to comply 26 + -- with `:h local-additions` template 27 + table.remove(lines, 1) 28 + table.remove(lines, 1) 29 + 30 + return lines 31 + end 32 + 33 + MiniDoc.generate(files, "doc/gopher.nvim.txt", { hooks = hooks })
+1
spec/minimal_init.lua scripts/minimal_init.lua
··· 26 26 27 27 install_plug "nvim-lua/plenary.nvim" 28 28 install_plug "nvim-treesitter/nvim-treesitter" 29 + install_plug "echasnovski/mini.doc" -- used for docs generation 29 30 30 31 vim.env.XDG_CONFIG_HOME = root ".tests/config" 31 32 vim.env.XDG_DATA_HOME = root ".tests/data"