Scripts2026年7月21日·1 分钟阅读

gopls — The Official Go Language Server

The official Go language server providing IDE features like auto-completion, go-to-definition, and diagnostics to any LSP-compatible editor.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
gopls Overview
直接安装命令
npx -y tokrepo@latest install 3c6ad7f3-84e1-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

gopls (pronounced "go please") is the official language server for Go, maintained by the Go team at Google. It implements the Language Server Protocol to bring rich IDE features — completion, navigation, refactoring, diagnostics — to any editor that speaks LSP.

What gopls Does

  • Provides intelligent auto-completion with type-aware suggestions and documentation
  • Implements go-to-definition, find-references, and rename across packages and modules
  • Runs real-time diagnostics including vet checks, staticcheck, and build errors
  • Supports code actions like organize imports, extract function, and generate tests
  • Handles workspace-wide symbol search and document outline

Architecture Overview

gopls runs as a long-lived process that communicates with editors over JSON-RPC. It loads Go modules using the standard go/packages API and builds an in-memory representation of the workspace. Incremental parsing and caching let it respond to edits without re-analyzing the entire module. It integrates analysis passes from the go/analysis framework for diagnostics.

Self-Hosting & Configuration

  • Install with go install golang.org/x/tools/gopls@latest; no separate runtime needed
  • Configure via editor-specific LSP settings or a gopls JSON settings block
  • Key settings include staticcheck (enable extra linters), gofumpt (stricter formatting), and analyses (toggle individual analyzers)
  • Memory usage scales with workspace size; large monorepos may need tuning via directoryFilters
  • Supports multi-module workspaces via the go.work file

Key Features

  • Zero-config setup for most editors — install and it works with Go modules out of the box
  • Integrated support for go generate, build tags, and CGo
  • Semantic token highlighting for richer syntax coloring
  • Inlay hints for parameter names, type parameters, and composite literal fields
  • Call hierarchy and implementation finder for navigating complex codebases

Comparison with Similar Tools

  • rust-analyzer — Equivalent LSP server for Rust; gopls mirrors its architecture for the Go ecosystem
  • TypeScript Language Server (tsserver) — Built into VS Code; gopls follows a similar approach but as a standalone binary
  • clangd — C/C++ language server; gopls is simpler to set up since Go tooling is self-contained
  • pyright — Python type-checking LSP; gopls benefits from Go's static type system for more precise analysis

FAQ

Q: Which editors support gopls? A: Any LSP-compatible editor including VS Code (via the Go extension), Neovim, Emacs, Sublime Text, and Helix.

Q: Does gopls replace goimports and gofmt? A: gopls runs organize-imports and formatting internally. You can still use standalone tools, but gopls handles them during save if configured.

Q: How much memory does gopls use? A: Typically a few hundred MB for medium projects. Large monorepos may need directoryFilters to limit scope.

Q: Is gopls maintained by the Go team? A: Yes, gopls is an official project under golang.org/x/tools, maintained by Google's Go team.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产