coc-golang
xiyaowongGo language support for coc.nvim using gopls
Published Package Summary
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.
Installation
Requirements
Install the extension from Vim or Neovim:
:CocInstall coc-golang
Open 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.
- Tests and benchmarks: run tests at package, workspace, file, or cursor scope; repeat the previous run; collect coverage; and run benchmarks.
- Project workflows: manage modules and workspaces, install Go tools, generate code or tests, edit struct tags, and generate interface implementations.
- Go environment: inspect Go settings and configure environments for
gopls, Go commands, and installed tools.
gopls handles language features. go run, go test, benchmarks, go doc, go get, go install and go mod init run in a coc.nvim terminal named Go; other command output is shown in the Go output channel.
Development
Install dependencies, then build and type-check:
npm install
npm run build
npm run typecheck
The build writes the extension bundles to lib/.
AI-assisted
Most of the code is AI-generated. Direction was manual.
Scope
The persistent VS Code test explorer, Delve debug adapter UI, survey and telemetry, coverage overlays, and rich diagnostic visualization are not included. Update checks cover gopls only.
- Go language support for coc.nvim using gopls
- onLanguage:go
- onLanguage:gomod
- onLanguage:gowork
- onCommand:go.test.package
- onCommand:go.test.explorer
- onCommand:go.test.workspace
- onCommand:go.test.file
- onCommand:go.test.cursor
- onCommand:go.test.cursorOrPrevious
- onCommand:go.subtest.cursor
- onCommand:go.benchmark.package
- onCommand:go.benchmark.cursor
- onCommand:go.benchmark.file
- onCommand:go.test.coverage
- onCommand:go.toggle.test.file
- onCommand:go.test.previous
- onCommand:go.build.package
- onCommand:go.vet.package
- onCommand:go.run
- onCommand:go.gopath
- onCommand:go.goroot
- onCommand:go.environment.choose
- onCommand:go.tools.install
- onCommand:go.languageserver.restart
- onCommand:go.build.workspace
- onCommand:go.vet.workspace
- onCommand:go.lint.package
- onCommand:go.lint.workspace
- onCommand:go.vulncheck.toggle
- onCommand:go.fmt.package
- onCommand:go.import.organize
- onCommand:go.import.add
- onCommand:go.generate.package
- onCommand:go.mod.tidy
- onCommand:go.mod.vendor
- onCommand:go.work.sync
- onCommand:go.mod.init
- onCommand:go.get.package
- onCommand:go.install.package
- onCommand:go.test.generate.file
- onCommand:go.test.generate.package
- onCommand:go.test.generate.function
- onCommand:go.tags.add
- onCommand:go.tags.remove
- onCommand:go.tags.clear
- onCommand:go.impl.cursor
- onCommand:go.test.cancel
- onCommand:go.test.showOutput
- onCommand:go.browse.packages
- onCommand:go.gopls.install
- onCommand:go.tools.install.dlv
- onCommand:go.tools.install.goimports
- onCommand:go.tools.install.staticcheck
- onCommand:go.tools.install.gomodifytags
- onCommand:go.tools.install.gotests
- onCommand:go.tools.install.impl
- onCommand:go.tools.install.gopls
- onCommand:go.version
- onCommand:go.env
- onCommand:go.locate.tools
- onCommand:go.tools.install.golint
- onCommand:go.tools.install.golangci-lint
- onCommand:go.tools.install.golangci-lint-v2
- onCommand:go.tools.install.revive
- onCommand:go.tools.install.gofumpt
- onCommand:go.tools.install.goformat
Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.
Open Developer GuideVersion History
Published with coc-golang@0.2.0 as CHANGELOG.md.
Contributed Commands
All contributes.commands entries from the published package manifest for coc-golang@0.2.0.
| Command (:CocCommand) | Description |
|---|---|
| go.test.package | Test Go Package |
| go.test.explorer | Pick a Go Test |
| go.test.workspace | Test Go Workspace |
| go.test.file | Test Go File |
| go.test.cursor | Test Go Function at Cursor |
| go.test.cursorOrPrevious | Test Go Function at Cursor or Repeat Previous |
| go.subtest.cursor | Test Go Subtest at Cursor |
| go.benchmark.package | Benchmark Go Package |
| go.benchmark.cursor | Benchmark Go Function at Cursor |
| go.benchmark.file | Benchmark Go File |
| go.test.coverage | Test Go Package with Coverage |
| go.toggle.test.file | Toggle Go Test File |
| go.test.previous | Repeat Previous Go Test |
| go.build.package | Build Go Package |
| go.vet.package | Vet Go Package |
| go.run | Run Go Package |
| go.env | Show Go Environment |
| go.gopath | Show GOPATH |
| go.goroot | Show GOROOT |
| go.environment.choose | Choose Go Environment |
| go.version | Show Go Version |
| go.tools.install | Install Go Tools |
| go.locate.tools | Locate Go Tools |
| go.languageserver.restart | Restart gopls |
| go.build.workspace | Build Go Workspace |
| go.vet.workspace | Vet Go Workspace |
| go.lint.package | Lint Go Package |
| go.lint.workspace | Lint Go Workspace |
| go.vulncheck.toggle | Toggle Vulncheck |
| go.fmt.package | Format Go Package |
| go.import.organize | Organize Go Imports |
| go.import.add | Add Go Import |
| go.generate.package | Generate Go Package |
| go.mod.tidy | Tidy Go Modules |
| go.mod.vendor | Vendor Go Modules |
| go.work.sync | Sync Go Workspace |
| go.mod.init | Initialize Go Module |
| go.get.package | Get Go Package |
| go.install.package | Install Go Package |
| go.test.generate.file | Generate Tests for Go File |
| go.test.generate.package | Generate Tests for Go Package |
| go.test.generate.function | Generate Test for Go Function |
| go.tags.add | Add Go Struct Tags |
| go.tags.remove | Remove Go Struct Tags |
| go.tags.clear | Clear Go Struct Tags |
| go.impl.cursor | Implement Go Interface |
| go.test.cancel | Cancel Go Tests |
| go.test.showOutput | Show Go Test Output |
| go.browse.packages | Browse Go Packages |
| go.gopls.install | Install or Update gopls |
| go.tools.install.dlv | Install Delve |
| go.tools.install.goimports | Install goimports |
| go.tools.install.staticcheck | Install Staticcheck |
| go.tools.install.gomodifytags | Install gomodifytags |
| go.tools.install.gotests | Install gotests |
| go.tools.install.impl | Install impl |
| go.tools.install.gopls | Install gopls |
| go.tools.install.golint | Install golint |
| go.tools.install.golangci-lint | Install golangci-lint |
| go.tools.install.golangci-lint-v2 | Install golangci-lint v2 |
| go.tools.install.revive | Install revive |
| go.tools.install.gofumpt | Install gofumpt |
| go.tools.install.goformat | Install goformat |
Configuration Schema
All contributes.configuration entries from the published package manifest, including each raw property schema for coc-settings.json.
Raw JSON Schema
{
"type": "object",
"default": {},
"markdownDescription": "Configure the default Go language server (`gopls`). Settings are passed to gopls as is; see the [gopls settings documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md). Dotted keys such as `\"ui.completion.usePlaceholders\"` are accepted.",
"additionalProperties": true
}Raw JSON Schema
{
"type": [
"string",
"null"
],
"default": null,
"description": "Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true."
}Raw JSON Schema
{
"type": [
"string",
"null"
],
"default": null,
"description": "Specifies the GOROOT to use when no environment variable is set."
}Raw JSON Schema
{
"type": "object",
"default": {},
"description": "Disable selected gopls language-client features."
}Raw JSON Schema
{
"enum": [
"staticcheck",
"golint",
"golangci-lint",
"golangci-lint-v2",
"revive"
],
"type": "string",
"description": "Specifies an additional client-side linting tool that should be run by the Go extension. By default (unset), no additional linter is run. This feature is additional to diagnostics reported by the language server, gopls. Since Gopls incorporates the entire staticcheck analyzer suite, it is typically unnecessary to run the staticcheck tool as well. To configure gopls's linting, see the 'gopls.ui.diagnostic' settings.",
"markdownEnumDescriptions": [
"Run `staticcheck`.",
"Run `golint`.",
"Run `golangci-lint` v1.",
"Run `golangci-lint` v2.",
"Run `revive`."
]
}Raw JSON Schema
{
"type": [
"string",
"null"
],
"default": null,
"description": "The Go build tags to use for when running tests. If null, then buildTags will be used."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Flags to pass to `go tool vet` (e.g. [\"-all\", \"-shadow\"]). Not applicable when using the language server's diagnostics."
}Raw JSON Schema
{
"type": "string",
"default": "",
"description": "The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.build.buildFlags` is not specified."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Flags to pass to Lint tool (e.g. [\"-min_confidence=.8\"])"
}Raw JSON Schema
{
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"default": null,
"description": "Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server."
}Raw JSON Schema
{
"enum": [
"package",
"workspace",
"off"
],
"type": "string",
"default": "package",
"description": "Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics.",
"enumDescriptions": [
"vet the current package on file saving",
"vet all the packages in the current workspace root folder on file saving",
"do not run vet automatically"
]
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. [\"-ldflags='-s'\"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified."
}Raw JSON Schema
{
"enum": [
"default",
"gofmt",
"goimports",
"goformat",
"gofumpt",
"custom"
],
"type": "string",
"default": "default",
"markdownDescription": "Specifies the tool for formatting Go code. The default is `default`, which uses the language server `gopls` as formatting provider. To configure gopls's formatting, see the 'gopls.formatting' settings. When a specific tool (e.g., `gofmt`, `goimports`) is selected, the extension will run it instead.",
"markdownEnumDescriptions": [
"Formatting is performed by the language server, gopls. (recommended)",
"Formats using `gofmt`, the standard Go formatter. See https://pkg.go.dev/cmd/gofmt.",
"Formats using `goimports`, which organizes imports and applies `gofmt`. See https://pkg.go.dev/golang.org/x/tools/cmd/goimports.",
"Formats using `goformat`, a configurable version of `gofmt`. See https://github.com/mbenkmann/goformat. (Deprecated due to lack of generics support)",
"Formats using `gofumpt`, a stricter version of `gofmt`. See https://github.com/mvdan/gofumpt. Note: `gopls` can also be configured to use `gofumpt` via the `#gopls.formatting.gofumpt#` setting.",
"Formats using a custom tool. The tool's path must be specified in the `#go.alternateTools#` setting under the `customFormatter` key."
]
}Raw JSON Schema
{
"enum": [
"file",
"package",
"workspace",
"off"
],
"type": "string",
"default": "package",
"description": "Lints code on file save using the configured Lint tool. Options are 'file', 'package', 'workspace' or 'off'.",
"enumDescriptions": [
"lint the current file on file saving",
"lint the current package on file saving",
"lint all the packages in the current workspace root folder on file saving",
"do not run lint automatically"
]
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled."
}Raw JSON Schema
{
"enum": [
"package",
"workspace",
"off"
],
"type": "string",
"default": "package",
"description": "Compiles code on file save using 'go build' or 'go test -c'. Not applicable when using the language server."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Flags to pass to format tool (e.g. [\"-s\"]). Not applicable when using the language server."
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "Infer GOPATH from the workspace root. This is ignored when using Go Modules."
}Raw JSON Schema
{
"type": "string",
"default": null,
"description": "Absolute path to a file containing environment variables definitions. File contents should be of the form key=value."
}Raw JSON Schema
{
"type": "object",
"default": {},
"description": "Environment variables that will be passed to the process that runs the Go tests"
}Raw JSON Schema
{
"type": "string",
"default": "30s",
"description": "Specifies the timeout for go test in ParseDuration format."
}Raw JSON Schema
{
"type": [
"string",
"null"
],
"default": null,
"description": "Location to install the Go tools that the extension depends on if you don't want them in your GOPATH."
}Raw JSON Schema
{
"type": "object",
"default": {},
"description": "Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with `envFile` and `env` values with precedence `env` > `envFile` > `go.toolsEnvVars`."
}Raw JSON Schema
{
"enum": [
"off",
"messages",
"verbose"
],
"type": "string",
"default": "off",
"description": "Trace the communication between VS Code and the Go language server. Also requires setting the 'gopls' output channel log level to 'Trace' ('Developer: Set Log Level...')."
}Raw JSON Schema
{
"type": "object",
"default": {},
"properties": {
"go": {
"type": "string",
"default": "go",
"description": "Alternate tool to use instead of the go binary or alternate path to use for the go binary."
},
"dlv": {
"type": "string",
"default": "dlv",
"description": "Alternate tool to use instead of the dlv binary or alternate path to use for the dlv binary."
},
"impl": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the impl binary or alternate path to use for the impl binary."
},
"gopls": {
"type": "string",
"default": "gopls",
"description": "Alternate tool to use instead of the gopls binary or alternate path to use for the gopls binary."
},
"golint": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the golint binary or alternate path to use for the golint binary."
},
"revive": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the revive binary or alternate path to use for the revive binary."
},
"gofumpt": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the gofumpt binary or alternate path to use for the gofumpt binary."
},
"gotests": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the gotests binary or alternate path to use for the gotests binary."
},
"goformat": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the goformat binary or alternate path to use for the goformat binary."
},
"goimports": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the goimports binary or alternate path to use for the goimports binary."
},
"staticcheck": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the staticcheck binary or alternate path to use for the staticcheck binary."
},
"gomodifytags": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the gomodifytags binary or alternate path to use for the gomodifytags binary."
},
"golangci-lint": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the golangci-lint binary or alternate path to use for the golangci-lint binary."
},
"customFormatter": {
"type": "string",
"default": "",
"markdownDescription": "Custom formatter to use instead of the language server. This should be used with the `custom` option in `#go.formatTool#`."
},
"golangci-lint-v2": {
"type": "string",
"default": "",
"description": "Alternate tool to use instead of the golangci-lint-v2 binary or alternate path to use for the golangci-lint-v2 binary."
}
},
"description": "Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools.",
"additionalProperties": true
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Additional arguments passed to go test benchmarks."
}Raw JSON Schema
{
"type": "object",
"default": {
"runtest": true
},
"properties": {
"runtest": {
"type": "boolean",
"default": true,
"description": "If true, enables code lens for running and debugging tests"
}
},
"description": "Feature level setting to enable/disable code lens for references and run/debug tests",
"additionalProperties": false
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Use the gopls remote daemon when supported."
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Ask to install gopls when it is not found."
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "Offer to install Go tools when a command needs a missing tool."
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Enable intellisense, code navigation, refactoring, formatting & diagnostics for Go. The features are powered by the Go language server \"gopls\"."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Additional command line flags to pass to `gotests` for generating tests."
}Raw JSON Schema
{
"type": "string",
"default": "",
"description": "The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation."
}Raw JSON Schema
{
"type": "array",
"default": [],
"description": "Flags like -rpc.trace and -logfile to be used while running the language server."
}Raw JSON Schema
{
"enum": [
"Imports",
"Off"
],
"type": "string",
"default": "Imports",
"markdownDescription": "(Experimental) vulncheck enables vulnerability scanning.\n",
"markdownEnumDescriptions": [
"`\"Imports\"`: In Imports mode, `gopls` will report vulnerabilities that affect packages\ndirectly and indirectly used by the analyzed main module.\n",
"`\"Off\"`: Disable vulnerability analysis.\n"
]
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"ignoredError\"` inlay hints for implicitly discarded errors:\n```go\n\tf.Close()« // ignore error»\n```\nThis check inserts an `// ignore error` hint following any\nstatement that is a function call whose error result is\nimplicitly ignored.\n\nTo suppress the hint, write an actual comment containing\none of the following strings:\n```\nignore error\ndiscard error\ncan't fail\ncannot fail\n```\nfollowing the call statement, or explicitly assign the\nresult to a blank variable.\n\nA handful of common functions such as `fmt.Println` are\nexcluded from the check.\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"constantValues\"` controls inlay hints for constant values:\n```go\n\tconst (\n\t\tKindNone Kind = iota« = 0»\n\t\tKindPrint« = 1»\n\t\tKindPrintf« = 2»\n\t\tKindErrorf« = 3»\n\t)\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"parameterNames\"` controls inlay hints for parameter names:\n```go\n\tparseInt(« str: » \"123\", « radix: » 8)\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "Automatically update the tools used by the extension, without prompting the user."
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Apply the Go & PATH environment variables used by the extension to all integrated terminals."
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"rangeVariableTypes\"` controls inlay hints for variable types in range statements:\n```go\n\tfor k« int», v« string» := range []string{} {\n\t\tfmt.Println(k, v)\n\t}\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"assignVariableTypes\"` controls inlay hints for variable types in assign statements:\n```go\n\ti« int», j« int» := 0, len(r)-1\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "If true, then `-i` flag will be passed to `go build` everytime the code is compiled. Since Go 1.10, setting this may be unnecessary unless you are in GOPATH mode and do not use the language server."
}Raw JSON Schema
{
"enum": [
"proxy",
"local",
"off"
],
"type": "string",
"default": "proxy",
"enumDescriptions": [
"keeps notified of new releases by checking the Go module proxy (GOPROXY)",
"checks only the minimum tools versions required by the extension",
"completely disables version check (not recommended)"
],
"markdownDescription": "Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"compositeLiteralTypes\"` controls inlay hints for composite literal types:\n```go\n\tfor _, c := range []struct {\n\t\tin, want string\n\t}{\n\t\t«struct{ in string; want string }»{\"Hello, world\", \"dlrow ,olleH\"},\n\t}\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"compositeLiteralFields\"` inlay hints for composite literal field names:\n```go\n\tPoint2D{«X: »1, «Y: »2}\n\n\tOuter{«Embedded.»Field: 0}\n```\n"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"markdownDescription": "`\"functionTypeParameters\"` inlay hints for implicit type parameters on generic functions:\n```go\n\tmyFoo«[int, string]»(1, \"hello\")\n```\n"
}