{"id":13410382,"url":"https://github.com/crispgm/nvim-go","last_synced_at":"2025-03-21T22:05:46.999Z","repository":{"id":36965910,"uuid":"343613705","full_name":"crispgm/nvim-go","owner":"crispgm","description":"A minimal implementation of Golang development plugin for Neovim","archived":false,"fork":false,"pushed_at":"2024-09-17T16:05:34.000Z","size":159,"stargazers_count":140,"open_issues_count":3,"forks_count":16,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-13T23:07:47.816Z","etag":null,"topics":["golang","golang-development","neovim","neovim-plugin"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crispgm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.buymeacoffee.com/crispgm"}},"created_at":"2021-03-02T01:53:07.000Z","updated_at":"2025-03-11T05:55:19.000Z","dependencies_parsed_at":"2023-12-29T10:21:33.117Z","dependency_job_id":"822a24c3-771d-43b8-b1f7-d544fea72e26","html_url":"https://github.com/crispgm/nvim-go","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crispgm%2Fnvim-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crispgm%2Fnvim-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crispgm%2Fnvim-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crispgm%2Fnvim-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crispgm","download_url":"https://codeload.github.com/crispgm/nvim-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244875013,"owners_count":20524591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-development","neovim","neovim-plugin"],"created_at":"2024-07-30T20:01:06.550Z","updated_at":"2025-03-21T22:05:46.975Z","avatar_url":"https://github.com/crispgm.png","language":"Lua","readme":"# nvim-go\n\n[![build](https://github.com/crispgm/nvim-go/actions/workflows/ci.yml/badge.svg)](https://github.com/crispgm/nvim-go/actions/workflows/ci.yml)\n\nA minimal implementation of Golang development plugin written in Lua for Neovim.\n\n## Introduction\n\nNeovim (from v0.5) embeds a built-in Language Server Protocol (LSP) client. And Debug Adapter Protocol (DAP) are also brought into Neovim as a general debugger. With the power of them, we are able to easily turn Neovim into a powerful editor.\n\n`nvim-go` is designed to collaborate with them, provides sufficient features, and leverages community toolchains to get Golang development done.\n\n## Features\n\n- Auto format with `:GoFormat` (via `goimports`, `gofmt`, `gofumpt` and `lsp`) when saving.\n- Run linters with `:GoLint` (via `revive`) automatically.\n- Quickly test with `:GoTest`, `:GoTestFunc`, `:GoTestFile` and `:GoTestAll`. Generate test with `:GoAddTest`.\n- Import packages with `:GoGet` and `:GoImport`.\n- Modify struct tags with `:GoAddTags`, `:GoRemoveTags`, `:GoClearTags`, `:GoAddTagOptions`, `:GoRemoveTagOptions` and `:GoClearTagOptions`.\n- Generates JSON models with `:GoQuickType` (via `quicktype`).\n- Generate if err based on function return values with `:GoIfErr` (via `iferr`).\n\n[Screenshots](https://github.com/crispgm/nvim-go/wiki#screenshots)\n\n## Recommended Features\n\nThis section can be regarded as a guide or common practice to develop with `nvim-go`, LSP (`gopls`) and DAP.\nIf you are familiar with these tools or other equivalent, you may skip this chapter.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u0026lt;Show/Hide the guide\u0026gt;\u003c/summary\u003e\n\n### Language Server\n\nLanguage server provides vital language features to make Golang development easy.\nWe highly recommend you to use LSP client together with `nvim-go`.\n\n1. Setup `gopls` with [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).\n2. Setup your favorite completion engine such as [nvim-cmp](https://github.com/hrsh7th/nvim-cmp).\n3. Setup and map the following methods based on what you need:\n\n- Declaration: `vim.lsp.buf.declaration()`\n- Definition: `vim.lsp.buf.definition()` and `vim.lsp.buf.type_definition()`\n- Implementation: `vim.lsp.buf.implementation()`\n- Hover: `vim.lsp.buf.hover()`\n- Signature: `vim.lsp.buf.signature_help()`\n- References: `vim.lsp.buf.reference()`\n- Symbols: `vim.lsp.buf.document_symbol()` and `vim.lsp.buf.workspace_symbol()`\n- Rename: `vim.lsp.buf.rename()`\n- Format: `vim.lsp.buf.format()`, also works with `GoFormat`.\n- Diagnostic: `vim.diagnostic` will also show lint issues with Virtual Text, which runs [`go/analysis`](https://github.com/golang/tools/tree/master/gopls/internal/lsp/analysis). You may disable `auto_lint` if this works well with your project.\n\nFor details of `gopls`, please refer to \u003chttps://github.com/golang/tools/blob/master/gopls/doc/design/design.md#features\u003e.\n\n### Debugger\n\n- [nvim-dap](https://github.com/mfussenegger/nvim-dap)\n\n\u003c/details\u003e\n\n## Installation\n\nPrerequisites:\n\n- Neovim (\u003e= 0.7)\n- [npm](https://www.npmjs.com) (for quicktype)\n\nInstall with your favorite package manager:\n\n```lua\n\" dependencies\nuse('nvim-lua/plenary.nvim')\n\n\" nvim-go\nuse('crispgm/nvim-go')\n\n\" (optional) if you enable nvim-notify\nuse('rcarriga/nvim-notify')\n\n\" (recommend) LSP config\nuse('neovim/nvim-lspconfig')\n```\n\nFinally, run `:GoInstallBinaries` after plugin installed.\n\n\u003e Install `quicktype` with `yarn` or `pnpm`:\n\n`nvim-go` install `quicktype` with `npm` by default, you may replace it with `yarn` or `pnpm`.\n\n```lua\nrequire('go').config.update_tool('quicktype', function(tool)\n    tool.pkg_mgr = 'yarn'\nend)\n```\n\n## Usage\n\n### Setup\n\n```lua\n-- setup nvim-go\nrequire('go').setup({})\n\n-- setup lsp client\nrequire('lspconfig').gopls.setup({})\n```\n\n### Defaults\n\n```lua\nrequire('go').setup({\n    -- notify: use nvim-notify\n    notify = false,\n    -- auto commands\n    auto_format = true,\n    auto_lint = true,\n    -- linters: revive, errcheck, staticcheck, golangci-lint\n    linter = 'revive',\n    -- linter_flags: e.g., {revive = {'-config', '/path/to/config.yml'}}\n    linter_flags = {},\n    -- lint_prompt_style: qf (quickfix), vt (virtual text)\n    lint_prompt_style = 'qf',\n    -- formatter: goimports, gofmt, gofumpt, lsp\n    formatter = 'goimports',\n    -- maintain cursor position after formatting loaded buffer\n    maintain_cursor_pos = false,\n    -- test flags: -count=1 will disable cache\n    test_flags = {'-v'},\n    test_timeout = '30s',\n    test_env = {},\n    -- show test result with popup window\n    test_popup = true,\n    test_popup_auto_leave = false,\n    test_popup_width = 80,\n    test_popup_height = 10,\n    -- test open\n    test_open_cmd = 'edit',\n    -- struct tags\n    tags_name = 'json',\n    tags_options = {'json=omitempty'},\n    tags_transform = 'snakecase',\n    tags_flags = {'-skip-unexported'},\n    -- quick type\n    quick_type_flags = {'--just-types'},\n})\n```\n\n### Manual\n\nDisplay within Neovim with:\n\n```vim\n:help nvim-go\n```\n\n## Advanced Configuration\n\n### Statusline Count\n\n[vim-airline](https://github.com/vim-airline/vim-airline):\n\n```lua\nfunction! LintIssuesCount()\n    if exists('g:nvim_go#lint_issues_count')\n        return g:nvim_go#lint_issues_count\n    endif\nendfunction\ncall airline#parts#define_function('nvim_go', 'LintIssuesCount')\ncall airline#parts#define_condition('nvim_go', '\u0026filetype == \"go\"')\nlet g:airline_section_warning = airline#section#create_right(['nvim_go'])\n```\n\n[lightline](https://github.com/itchyny/lightline.vim):\n\n```lua\nfunction! LintIssuesCount()\n    if exists('g:nvim_go#lint_issues_count') \u0026\u0026 \u0026filetype == 'go'\n        return g:nvim_go#lint_issues_count\n    endif\nendfunction\nlet g:lightline = {\n  \\ 'colorscheme': 'wombat',\n  \\ 'active': {\n  \\   'left': [ [ 'mode', 'paste' ],\n  \\             [ 'readonly', 'filename', 'modified', 'lintcount' ] ]\n  \\ },\n  \\ 'component_function': {\n  \\   'lintcount': 'LintIssuesCount'\n  \\ },\n  \\ }\n```\n\n[nvim-hardline](https://github.com/ojroques/nvim-hardline):\n\n```lua\nrequire('hardline').setup({\n    -- ...\n    sections = {\n        {\n            class = 'error',\n            item = function()\n                if\n                    vim.bo.filetype == 'go'\n                    and vim.g['nvim_go#lint_issues_count'] ~= nil\n                then\n                    return vim.g['nvim_go#lint_issues_count']\n                else\n                    return ''\n                end\n            end,\n        },\n    -- ...\n    }\n```\n\n### Show Lint Issues without Focusing\n\n```viml\naugroup NvimGo\n  autocmd!\n  autocmd User NvimGoLintPopupPost wincmd p\naugroup END\n```\n\nOr equivalently:\n\n```lua\nlocal NvimGo = vim.api.nvim_create_augroup(\"NvimGo\", {\n  clear = true,\n})\nvim.api.nvim_create_autocmd({ \"User\" }, {\n  pattern = \"NvimGoLintPopupPost\",\n  group = NvimGo,\n  command = \"wincmd p\",\n})\n```\n\n## License\n\n[MIT](/LICENSE)\n","funding_links":["https://www.buymeacoffee.com/crispgm"],"categories":["Programming Languages Support","Lua"],"sub_categories":["Golang"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrispgm%2Fnvim-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrispgm%2Fnvim-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrispgm%2Fnvim-go/lists"}