coc-golang
v0.9.0
Published
Rich Go Development for coc.nvim
Maintainers
Readme
Logo concept by @xiyaowong, drawn with AI
coc-golang
Go language support for coc.nvim, powered by the official gopls language server and Go tools.
Install · Features · Commands · Configuration · Development
🧭 Overview
coc-golang brings Go development features to Vim and Neovim through coc.nvim. It uses gopls for language intelligence and provides commands for testing, building, formatting, linting, vulnerability checks, and common Go project tasks.
🤖 AI-assisted
To be upfront: this project is vibe-coded, and most of the code is AI-generated.
What it is not is AI slop. Every feature goes through repeated rounds of tweaking and is tested by hand before it lands — nothing is merged straight from a model's output. The direction follows vscode-go, with some features designed by me, and the polish took real effort. If vibe coding puts you off, this extension is not for you.
📦 Installation
📋 Requirements
Install the extension from Vim or Neovim:
:CocInstall coc-golangOpen a Go file to activate the extension. If gopls is not installed, coc-golang prompts you to install it. You can also install it at any time with:
:CocCommand go.gopls.install✨ Features
- 🧠 Language intelligence: completion, hover, signature help, diagnostics, navigation, references, rename, code actions, and document symbols through
gopls. - 🧹 Formatting and imports: format Go code and add or organize imports.
- 🏗️ Build and checks: build, run, vet, lint, and scan packages or workspaces for known vulnerabilities.
- 🔎 Diagnostics: errors and warnings from
goplsand from build, vet, and lint runs, each carrying the analyzer or check code, a link to its documentation, and the range the tool pointed at. - 🧪 Tests and benchmarks: run tests at package, workspace, file, or cursor scope; browse and run them from a tree view with pass/fail status; repeat the previous run; collect coverage and show each block's execution count; and run benchmarks.
- 📁 Project workflows: manage modules and workspaces, install Go tools, generate code or tests, edit struct tags, and generate interface implementations.
- 🔍 Package search: search pkg.go.dev and
get,install, ordownloadwhat you find without leaving the editor. - 🔄 Converters: generate Go types from a JSON Schema or from JSON.
- 🌱 Go environment: inspect Go settings and configure environments for
gopls, Go commands, and installed tools.
gopls handles language features. The commands below run either in a coc.nvim terminal named Go (go run, go test, benchmarks, go doc, go get, go install, go mod init) or in the Go output channel (everything else).
💻 Commands
Run commands with :CocCommand, for example:
:CocCommand go.test.packageThe ones you'll reach for most:
| Task | Command |
| --- | --- |
| Run tests in the current package | go.test.package |
| Run the test at the cursor | go.test.cursor |
| Run the tests in the current file | go.test.file |
| Toggle coverage for the current package | go.test.coverage |
| Build the current package | go.build.package |
| Vet the current package | go.vet.package |
| Format the current package | go.fmt.package |
| Organize imports | go.import.organize |
| Show the Go environment | go.env |
| Install a Go tool | go.tools.install |
| Search packages on pkg.go.dev | go.pkg.search |
Every go.* command — all 83, grouped by area — is in the command reference.
Some commands need an extra tool: test generation uses gotests, struct tags use gomodifytags, and interface generation uses impl. Vulnerability analysis is provided by gopls.
🔍 Package search
go.pkg.search searches pkg.go.dev for a package and acts on what it finds. Each action runs a go command:
| Action | Command |
| --- | --- |
| get (default) | go get <packagePath> |
| install | go install <packagePath> |
| download | go mod download <modulePath> |
Several packages can be picked at once.
See Package search for the details.
🌳 Test explorer
go.test.explorer.show opens a Go Tests tree view of your workspace's tests and benchmarks:
- Nested
folder → package → file → test → subtest. - Run any node — a file, package, or folder runs everything beneath it.
- Pass/fail status on every node, plus a location to jump to.
- Press
fto filter the tree by name.
go.test.explorer remains as the quick-pick alternative.
See Test explorer for the details.
🔄 Converters
go.convert.jsonSchemaGenerate Go types from a JSON Schema.go.convert.jsonToGoGenerate Go types from JSON.
go.convert.jsonSchema runs go-jsonschema on the active JSON Schema file and opens the generated Go. Schemas that use the date or date-time formats make the generated code import github.com/atombender/go-jsonschema/pkg/types.
go.convert.jsonToGo opens a scratch JSON buffer and a scratch Go buffer side by side, regenerating the Go types as you type. The JSON can come from the clipboard, from a file, or from an empty buffer.
The generated Go matches the defaults of mholt/json-to-go and needs no extra tool.
See Converters for the details.
🔖 Struct tags
go.tags.add, go.tags.remove, and go.tags.clear run gomodifytags on the struct or field under the cursor, or on a visual selection.
🌱 Go environment and tools
Commands for the Go environment and tools:
go.env,go.gopath,go.goroot,go.version,go.environment.choose— inspect or select the Go environment.go.locate.tools— locate installed tools.go.tools.install,go.tools.install.<tool>— install tools.go.gopls.install— installgopls.go.languageserver.restart— restartgopls.
Optional tools are dlv, goimports, staticcheck, gomodifytags, gotests, impl, golint, golangci-lint, golangci-lint-v2, revive, gofumpt, goformat, and go-jsonschema. Delve works with external DAP clients; coc-golang provides no debug adapter UI.
🔧 Configuration
Add settings to coc-settings.json. For example:
{
"go.useLanguageServer": true,
"go.autoInstallGopls": true,
"go.languageServerFlags": [],
"go.goplsUseDaemon": true,
"gopls": {},
"go.buildFlags": [],
"go.buildTags": "",
"go.formatTool": "default",
"go.testTimeout": "30s",
"go.testOnSave": false,
"go.diagnostic.vulncheck": "Imports"
}Setting names, types, and defaults follow vscode-go. The gopls setting accepts gopls options, including dotted keys.
Go-specific settings such as build flags, build tags, inlay hints, vulnerability checks, and code lenses are forwarded to gopls unless explicitly set there. Vulnerability analysis uses gopls' import-based diagnostics and built-in govulncheck code lens/quick fix; go.vulncheck.toggle enables or disables the import-based diagnostics.
Some settings to know:
- Go environment:
go.goroot,go.gopath,go.toolsEnvVars,go.toolsGopath, andgo.alternateToolscontrol the environment and executable paths used by Go commands,gopls, and tool installs. Setgo.terminal.activateEnvironmentto export the configured environment to Neovim. - Formatting:
go.formatToolsupportsgofmt,goimports,goformat,gofumpt, andcustom. Withgo.useLanguageServer: false, the default formatter usesgoimports. - Checks: build and vet on save run when
go.useLanguageServerisfalse. Lint on save runs whengo.lintToolis configured. Available lint tools arestaticcheck,golint,golangci-lint,golangci-lint-v2, andrevive; diagnostics are reported by coc.nvim. - Tests:
go.testFlagsandgo.testTagsfall back togo.buildFlagsandgo.buildTags.go.testTimeoutsupplies the test timeout, andgo.testEnvFileis loaded beforego.testEnvVars. - Coverage:
go.test.coveragetoggles coverage for the current package: it runsgo test -coverprofile, then highlights covered code (CocCoverageCovered) and uncovered code (CocCoverageUncovered) in the loaded Go buffers. Running it again, or saving an edited Go file, clears the highlights.go.apply.coverprofilehighlights from an existing profile: it offers the profiles of previous runs, or takes a path of your own.go.show.coverprofileopens a profile — one of those runs, or a path of your own — in a buffer.go.coverModesets-covermode, andgo.coverShowCountsappends each covered block's execution count as virtual text. - Language server: set
go.useLanguageServertofalseto disablegoplsand use Go commands and formatters directly.
🚧 Development
Install dependencies, then build and type-check:
npm install
npm run build
npm run typecheckThe build writes the extension bundles to lib/.
📝 Changelog
See CHANGELOG.md.
🎯 Scope
Not included:
- The VS Code test explorer's run/debug gutter and status-bar widgets.
- The Delve debug adapter UI.
- Survey and telemetry.
Update checks cover gopls only. Coverage highlighting is simpler than vscode-go's: covered and uncovered line ranges, with no gutter icons or per-block style settings.
🤖 For AI agents
If you are an AI agent working on this repository, read and follow AGENTS.md in the repository root. It is the source of truth for the project's conventions, and it overrides any default behavior.
