Gopls LSP
Verified@bowen31337
npx machina-cli add skill @bowen31337/gopls-lsp --openclawgopls LSP
Go language server integration providing comprehensive code intelligence through gopls (the official Go language server).
Capabilities
- Code intelligence: Autocomplete, go-to-definition, find references
- Error detection: Real-time diagnostics for compilation errors and issues
- Refactoring: Rename symbols, extract function, organize imports
- Analysis: Static analysis, code suggestions, unused code detection
- Supported extensions:
.go
Installation
Install gopls using the Go toolchain:
go install golang.org/x/tools/gopls@latest
Important: Make sure $GOPATH/bin (or $HOME/go/bin) is in your PATH.
Verify installation:
gopls version
Usage
The language server runs automatically in LSP-compatible editors. For manual operations:
Format code
gofmt -w file.go
Run linter
go vet ./...
Build and test
go build ./...
go test ./...
Configuration
Create gopls.yaml in your project or workspace for custom settings:
analyses:
unusedparams: true
shadow: true
completeUnimported: true
staticcheck: true
Or configure via environment:
export GOPLS_CONFIG='{"staticcheck": true, "analyses": {"unusedparams": true}}'
Integration Pattern
When editing Go code:
- gopls provides real-time diagnostics in LSP editors
- Run
go fmtorgofmtto format code - Use
go vetfor additional static analysis - Run tests with
go testbefore committing
Common Go Commands
go mod init <module>- Initialize Go modulego mod tidy- Clean up dependenciesgo get <package>- Add dependencygo build- Compile packagesgo run main.go- Run programgo test- Run testsgo vet- Report suspicious constructs
More Information
Overview
gopls LSP provides comprehensive code intelligence for Go development by running the official Go language server inside your editor. It delivers autocomplete, go-to-definition, find references, real-time diagnostics, and refactoring support for .go files, along with static analysis and import-management features.
How This Skill Works
gopls runs as a Language Server Protocol service that communicates with LSP-enabled editors to provide diagnostics, completions, symbol navigation, and refactoring actions. Install the tool with: go install golang.org/x/tools/gopls@latest and ensure the gopls binary is on your PATH; per-project settings can be declared in gopls.yaml or via the GOPLS_CONFIG environment variable.
When to Use It
- You are editing Go code and need autocomplete, go-to-definition, or find references.
- You want reliable real-time diagnostics for compilation errors and warnings as you type.
- You need safe refactoring (rename, extract function, organize imports) across a Go codebase.
- You want static analysis and unused-code detection to improve code quality.
- You are setting up a new Go project or workspace and want consistent tooling in an LSP editor.
Quick Start
- Step 1: Install gopls: go install golang.org/x/tools/gopls@latest
- Step 2: Ensure PATH includes GOPATH/bin or $HOME/go/bin and verify with gopls version
- Step 3: Open a Go project in an LSP-compatible editor and optionally create gopls.yaml or set GOPLS_CONFIG
Best Practices
- Install and keep gopls updated with go install golang.org/x/tools/gopls@latest.
- Enable the analyses and static checks you need in gopls.yaml (e.g., unusedparams, shadow, staticcheck).
- Optionally set GOPLS_CONFIG for consistent behavior across environments.
- Add GOPATH/bin or $HOME/go/bin to your PATH so gopls is executable from the editor.
- Use in combination with go fmt/go vet and go test to maintain code quality.
Example Use Cases
- A Go developer enables gopls in VS Code to get real-time diagnostics and hover-based definitions while refactoring.
- A team uses gopls to automatically organize imports and detect unused parameters across a large codebase.
- Gopls-powered editors surface go-to-definition and find references when navigating packages.
- Static analysis via staticcheck in gopls.yaml catches issues before commits.
- New Go projects are set up with a consistent lsp workflow, ensuring code formatting and tests run smoothly before push.