A “code lens” is a command associated with a range of a source file. The VS Code manual describes code lenses as “actionable, contextual information, interspersed in your source code”. The LSP textDocument/codeLens operation requests the current set of code lenses for a file.
Gopls generates code lenses from a number of sources. This document describes them.
They can be enabled and disabled using the codelenses setting. Their features are subject to change.
Client support:
gopls codelens. For example, gopls codelens -exec file.go:123 "run test" runs the test at the specified line.generate: Run go generateThis codelens source annotates any //go:generate comments with commands to run go generate in this directory, on all directories recursively beneath this one.
See Generating code for more details.
Default: on
File type: Go
regenerate_cgo: Re-generate cgo declarationsThis codelens source annotates an import "C" declaration with a command to re-run the cgo command to regenerate the corresponding Go declarations.
Use this after editing the C code in comments attached to the import, or in C header files included by it.
Default: on
File type: Go
test: Run tests and benchmarksThis codelens source annotates each Test and Benchmark function in a *_test.go file with a command to run it.
This source is off by default because VS Code has a client-side custom UI for testing, and because progress notifications are not a great UX for streamed test output. See:
Default: off
File type: Go
run_govulncheck: Run govulncheck (legacy)This setting is experimental and may be deleted.
This codelens source annotates the module directive in a go.mod file with a command to run Govulncheck asynchronously.
Govulncheck is a static analysis tool that computes the set of functions reachable within your application, including dependencies; queries a database of known security vulnerabilities; and reports any potential problems it finds.
Default: off
File type: go.mod
tidy: Tidy go.mod fileThis codelens source annotates the module directive in a go.mod file with a command to run go mod tidy, which ensures that the go.mod file matches the source code in the module.
Default: on
File type: go.mod
upgrade_dependency: Update dependenciesThis codelens source annotates the module directive in a go.mod file with commands to:
Default: on
File type: go.mod
vendor: Update vendor directoryThis codelens source annotates the module directive in a go.mod file with a command to run go mod vendor, which creates or updates the directory named vendor in the module root so that it contains an up-to-date copy of all necessary package dependencies.
Default: on
File type: go.mod
vulncheck: Run govulncheckThis setting is experimental and may be deleted.
This codelens source annotates the module directive in a go.mod file with a command to run govulncheck synchronously.
Govulncheck is a static analysis tool that computes the set of functions reachable within your application, including dependencies; queries a database of known security vulnerabilities; and reports any potential problems it finds.
Default: off
File type: go.mod