Enhance your golang experience
Find a file
Smirnov Oleksandr 52b629c14d test: add config
2022-06-27 19:03:33 +03:00
.github/workflows chore: add CI 2022-06-17 21:58:03 +03:00
autoload/health feat: add health checker 2022-06-07 01:08:33 +03:00
lua/gopher fix typo [skip ci] 2022-06-27 19:03:33 +03:00
plugin feat(gotests): generate tests only for exported func 2022-06-23 13:24:29 +03:00
spec test: add config 2022-06-27 19:03:33 +03:00
.gitignore Initial commit 2022-05-30 15:44:12 +03:00
.pre-commit-config.yaml fix(pre-commit): check stylua instead of format 2022-06-17 22:35:59 +03:00
Makefile add makefile 2022-05-31 00:23:53 +03:00
nvim.toml Initial commit 2022-05-30 15:44:12 +03:00
README.md docs: add config 2022-06-27 19:03:33 +03:00
selene.toml Initial commit 2022-05-30 15:44:12 +03:00
stylua.toml Initial commit 2022-05-30 15:44:12 +03:00

gopher.nvim

Minimalistic plugin for Go development in Neovim written in Lua.

It's not an LSP tool, the main goal of this plugin add go tooling support in neovim.

Install

Pre-dependency: go (tested on 1.17 and 1.18)

use {
  "olexsmir/gopher.nvim",
  requires = { -- dependencies
    "nvim-lua/plenary.nvim",
    "nvim-treesitter/nvim-treesitter",
  },
}

Also, run TSInstall go if install the go parser if not installed yet.

Config

By .setup function you can configure the plugin.

Note:

  • Installer does not install the tool in user set path
require("gopher").setup {
  commands = {
    go = "go",
    gomodifytags = "gomodifytags",
    gotests = "~/go/bin/gotests", -- also you can set custom command path
    impl = "impl",
  },
}

Features

  1. Install requires go tools:
:GoInstallDeps

This will install next tools:

  1. Modify struct tags: By default be added/removed json tag, if not set.
:GoTagAdd json " For add json tag
:GoTagRm yaml " For remove yaml tag
  1. Run go mod command
:GoMod tidy " Runs `go mod tidy`
:GoMod init asdf " Runs `go mod init asdf`
  1. Run go get command

Link can has a http or https prefix.

You can provide more that one package url.

:GoGet github.com/gorilla/mux
  1. Interface implementation

Command syntax:

:GoImpl [receiver] [interface]

" Also you can put cursor on the struct and run:
:GoImpl [interface]

Example of usage:

" Example
:GoImpl r Read io.Reader
" or simply put your cursor in the struct and run:
:GoImpl io.Reader
  1. Generate tests with gotests

Generate one test for spesific function/method

:GoTestAdd

Generate all tests for all functions/methods in current file

:GoTestsAll

Generate tests only for exported functions/methods in current file

:GoTestsExp
  1. Run go generate command
" Run `go generate` in cwd path
:GoGenerate

" Run `go generate` for current file
:GoGenerate %

Thanks