A VS Code extension that shows memory size and padding information for Go structs, now powered by a Go LSP backend for exact fieldalignment parity.
- Hover Information — hover over struct fields to see size, alignment, offset, and padding
- Inline Annotations — code lens showing struct/field sizes and GC scan info directly in the editor
- Optimization Warnings — real-time yellow underline when struct layout wastes memory
- GC Pressure Hints — blue underline when pointer field reordering reduces GC scan range
- Quick Fix — one-click reorder for memory layout and GC pressure issues (preserves tags, comments, indentation)
- Side Panel — side-by-side Current and Optimal layouts
- Architecture Support — configurable target (amd64, 386, arm64, arm)
code --install-extension PatricioDiaz.go-struct-analyzerDownload the .vsix from GitHub Releases:
code --install-extension go-struct-analyzer-*.vsixCursor: Extensions → "..." → Install from VSIX.
Open any Go file. Hover over a struct field to see its layout. When a struct shows a yellow warning, click the lightbulb or press Ctrl+. to reorder fields for optimal size:
type Event struct { // ⚠️ 40 bytes (can be 24 bytes)
A bool // 1B
B int64 // 8B (+7B padding)
C bool // 1B
D int64 // 8B (+7B padding)
E int32 // 4B
F bool // 1B (+3B padding)
}After quick fix:
type Event struct { // ✓ 24 bytes, -16B
B int64 // 8B
D int64 // 8B
E int32 // 4B
A bool // 1B
C bool // 1B
F bool // 1B (+1B padding)
}The extension ships gsa-lsp — a standalone Go binary for struct analysis outside VS Code:
gsa-lsp analyze [--arch amd64] file.go # JSON output
gsa-lsp lsp # LSP server (stdin/stdout)
gsa-lsp version # version infoInstall from source:
make build-go # builds gsa-lsp to project root
make install # copies to $GOPATH/binInstall via curl (recommended):
curl -fsSL https://padiazg.github.io/go-struct-analyzer/install.sh | shInstall a specific version:
curl -fsSL https://padiazg.github.io/go-struct-analyzer/install.sh | sh -s -- -v v2.0.4gsa-lsp is a standard LSP server — use it with any LSP-compatible editor alongside gopls:
gsa-lsp lsp # stdin/stdout JSON-RPCSupported LSP methods: textDocument/hover, textDocument/codeLens, textDocument/codeAction, textDocument/publishDiagnostics.
Emacs: see the Emacs setup guide for eglot (Emacs 29+) and lsp-mode.
Neovim: see the Neovim setup guide for built-in LSP client config.
Helix (~/.config/helix/languages.toml):
[language-server.gsa-lsp]
command = "gsa-lsp"
args = ["lsp"]
[[language]]
name = "go"
language-servers = ["gsa-lsp"]Zed (experimental): install the dev extension from editors/zed/ via zed: install dev extension. See editors/zed/README.md. The binary must be on PATH.
Best experience is the VS Code extension (inline annotations, side panel). Other editors get hover info, diagnostics, and code actions only.
| Setting | Default | Description |
|---|---|---|
showInlineAnnotations |
false |
Show size annotations inline |
showPadding |
true |
Highlight padding bytes |
architecture |
amd64 |
Target architecture |
enableStructOptimizationWarnings |
true |
Warnings for sub-optimal layout |
enableReorderCodeAction |
true |
Quick fix for field reorder |
reorderCodeActionPreferred |
false |
Enable source.fixAll |
enableGCPressureWarnings |
true |
GC scan range hints |
gcPressureSeverityWarning |
false |
GC hints as warnings (yellow underline) instead of hints (...) |
All settings are prefixed with goStructAnalyzer. (e.g. goStructAnalyzer.architecture).
- Full user documentation — detailed guides for all features
- Configuration — all settings reference
- Memory alignment concepts — how Go struct alignment works
- GC scan range — understanding GC pressure
git clone https://github.com/padiazg/go-struct-analyzer
cd go-struct-analyzer
make build # Go binary + TypeScript
# or: make build-go # Go binary only
# or: make build-ts # TypeScript onlyPrerequisites: Go 1.21+, Node.js 22+
See CONTRIBUTING.md for setup, project structure, coding guidelines, and PR process.
See changelog.md for version history.
v2.0.4: Server version compatibility check — extension stops if gsa-lsp major version mismatches. curl installer served from GitHub Pages.
MIT — see LICENSE.
- fieldalignment — the GC pointer scan range concept that inspired the GC pressure analysis.