Get the FREE Ultimate OpenClaw Setup Guide →
b

Gopls LSP

Verified

@bowen31337

npx machina-cli add skill @bowen31337/gopls-lsp --openclaw
Files (1)
SKILL.md
2.2 KB

gopls 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:

  1. gopls provides real-time diagnostics in LSP editors
  2. Run go fmt or gofmt to format code
  3. Use go vet for additional static analysis
  4. Run tests with go test before committing

Common Go Commands

  • go mod init <module> - Initialize Go module
  • go mod tidy - Clean up dependencies
  • go get <package> - Add dependency
  • go build - Compile packages
  • go run main.go - Run program
  • go test - Run tests
  • go vet - Report suspicious constructs

More Information

Source

git clone https://clawhub.ai/bowen31337/gopls-lspView on GitHub

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

  1. Step 1: Install gopls: go install golang.org/x/tools/gopls@latest
  2. Step 2: Ensure PATH includes GOPATH/bin or $HOME/go/bin and verify with gopls version
  3. 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.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers