Go Usage Finder
A powerful VSCode extension that finds all references (read/write) for Go symbols (fields, functions, variables) across your entire codebase, including GOROOT and external libraries.
Features
🔍 Comprehensive Reference Search: Find all references to Go symbols across:
- Current workspace/project
- GOROOT (Go standard library)
- External libraries (go modules)
📖 Read/Write Distinction: Clearly distinguishes between:
- Read references: Variable/field reads, function calls
- Write references: Assignments, increments/decrements, mutations
🎯 Bottom Panel View: Dedicated panel at the bottom showing references organized by:
- Reference type (Read/Write)
- Scope (Workspace/GOROOT/External Libraries)
- Hierarchical directory structure
- File nodes with reference counts
⚡ Quick Navigation: Click any reference to preview it side-by-side without losing focus
👁️ Peek View Preview: View references in a floating preview window without leaving your current file
Installation
From VSCode Marketplace
- Open VSCode
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Go Usage Finder"
- Click Install
From VSIX
- Download the
.vsix file
- Open VSCode
- Go to Extensions
- Click "..." menu → "Install from VSIX..."
- Select the downloaded file
Requirements
- VSCode 1.85.0 or higher
- Go installed and available in PATH
- Go extension for VSCode (recommended)
gopls (Go language server) installed for enhanced searching
Installation
From Source
- Clone or download this repository
- Open the folder in VSCode
- Run
npm install to install dependencies
- Run
npm run compile to compile the extension
- Press
F5 to launch the extension in debug mode
Installing gopls (if not already installed)
go install golang.org/x/tools/gopls@latest
Usage
Finding References
Method 1: Tree View (Full List)
- Open a Go file in VSCode
- Place your cursor on a variable, function, or field name
- Right-click and select "Go: Find All References (Read/Write)"
- Or use the command palette (
Cmd+Shift+P / Ctrl+Shift+P) and search for "Go: Find All References"
- View results in the "Go References" panel at the bottom
Method 2: Peek View (Quick Preview)
- Place your cursor on a symbol
- Right-click and select "Show References in Peek View"
- A floating window will show all references with inline code preview
- Navigate with arrow keys, press Enter to jump to a reference
Viewing Results
Bottom Panel:
The extension displays results in the "Go References" panel at the bottom of the window:
- 📖 Read References: Shows all places where the symbol is read or called (blue eye icon)
- ✏️ Write References: Shows all places where the symbol is modified (red edit icon)
- 📁 Workspace: References in your current project
- 🔧 GOROOT: References in Go standard library
- 📦 External Libraries: References in third-party modules
The panel shows a hierarchical structure:
- Folders: Organized by directory path
- Files: Each file shows reference count
- References: Line number with code snippet preview (first 60 characters)
- Hover over any item to see full path
Peek View:
The peek view shows a floating window with:
- All references listed on the left
- Full code context on the right
- Syntax highlighting
- Quick navigation with keyboard
Navigation
From Bottom Panel:
- Click on any reference to preview it side-by-side in the right editor
- The preview opens without stealing focus from the panel
- Hover over references to see the full file path and code context
- Use the refresh button (top-right of panel) to re-run the search
- Expand/collapse folders to navigate the directory structure
From Peek View:
- Use arrow keys to navigate between references
- Press
Enter to jump to the selected reference
- Press
Escape to close the peek view
- Click on any reference to open it in the editor
How It Works
The extension uses multiple strategies to find references:
- VSCode Built-in Provider: Uses VSCode's reference provider for fast local searches
- gopls Integration: Leverages the Go language server for comprehensive cross-package searches
- Scope Detection: Analyzes file paths to determine if references are in:
- Workspace (your project files)
- GOROOT (Go standard library)
- External libraries (go.mod dependencies)
- Read/Write Analysis: Examines the code context to determine if a reference is a read or write operation
Configuration
No configuration required! The extension automatically detects your Go environment using go env.
Known Limitations
- Write detection is heuristic-based and may not catch all edge cases
- Very large codebases may take longer to search
- Requires
gopls for searching in external libraries
Troubleshooting
No references found in external libraries
- Ensure
gopls is installed: go install golang.org/x/tools/gopls@latest
- Check that
gopls is in your PATH
- Try running
gopls version in terminal to verify installation
Extension not activating
- Ensure you're working with Go files (
.go extension)
- Check that the Go extension is installed and working
Development
Building
npm install
npm run compile
Running in Debug Mode
Press F5 in VSCode to launch the extension development host.
Project Structure
go-usage/
├── src/
│ ├── extension.ts # Extension entry point
│ ├── usageProvider.ts # Tree view provider
│ └── referenceFinder.ts # Reference finding logic
├── package.json # Extension manifest
└── tsconfig.json # TypeScript configuration
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
MIT
Changelog
0.0.1
- Initial release
- Find references across workspace, GOROOT, and external libraries
- Read/Write distinction
- Custom tree view for displaying results