Go Mod Size Viewer
A Visual Studio Code extension that displays the disk size of Go module dependencies in go.mod files.
Features
- 📦 Package Size Display: View the disk size of each dependency
- 🎯 Two Display Modes:
- Hover Mode: Shows size when you hover over a package (default)
- Inlay Mode: Displays sizes inline as hints
- ⚡ Smart Caching: Caches results to avoid repeated calculations
- 🎨 Customizable: Configure display units and cache duration
- 🚀 Lightweight: Runs independently without affecting gopls performance
Usage
Hover Mode (Default)
Simply hover over any require line in your go.mod file:
require (
github.com/gin-gonic/gin v1.9.1 // Hover to see size
github.com/pkg/errors v0.9.1 // Hover to see size
)
You'll see a popup showing:
- Package name and version
- Total size
- Number of files
- Local path
Inlay Hints Mode
Enable inlay hints in settings to see sizes inline:
require (
github.com/gin-gonic/gin v1.9.1 // 2.3 MB
github.com/pkg/errors v0.9.1 // 156 KB
)
Configuration
Open VS Code settings and search for "Go Mod Size Viewer":
{
// Enable/disable the extension
"gomodSizeViewer.enabled": true,
// Display mode: "hover" or "inlay"
"gomodSizeViewer.displayMode": "hover",
// Cache duration in seconds (default: 1 hour)
"gomodSizeViewer.cacheDuration": 3600,
// Size unit: "auto", "KB", "MB", or "GB"
"gomodSizeViewer.unit": "auto"
}
Commands
- Go Mod Size Viewer: Clear Cache - Clear all cached size data
- Go Mod Size Viewer: Refresh - Recalculate sizes for current file
Access commands via Command Palette (Cmd/Ctrl + Shift + P)
Requirements
- Visual Studio Code 1.80.0 or higher
- Go modules must be downloaded to
$GOPATH/pkg/mod
- For Unix/Linux/Mac: Works best with
du and find commands available
How It Works
- Parses
require statements in go.mod
- Locates packages in
$GOPATH/pkg/mod directory
- Calculates directory size using:
- Native
du command on Unix/Linux/Mac (fast)
- Recursive file traversal on Windows (cross-platform)
- Caches results to improve performance
- First calculation for each package may take a few seconds
- Results are cached for the configured duration (default: 1 hour)
- Calculations run asynchronously without blocking the editor
- Independent from gopls - doesn't affect Go language features
Limitations
- Only shows sizes for already downloaded packages
- Requires packages to exist in
$GOPATH/pkg/mod
- May be slower on network file systems
- Windows: Uses recursive traversal (slower than Unix
du command)
Troubleshooting
Size not showing?
- Ensure the package is downloaded:
go mod download
- Check that
$GOPATH is set correctly
- Verify the package exists in
$GOPATH/pkg/mod
Slow performance?
- Increase cache duration in settings
- Switch to hover mode if using inlay mode
- Clear cache if it becomes stale
Contributing
Issues and pull requests are welcome on GitHub.
License
MIT License - see LICENSE file for details
Credits
Inspired by the feature request: golang/vscode-go#3667