Overview
The References tool finds all usages of a symbol (function, variable, type, etc.) across your codebase using the Language Server Protocol (LSP). This provides semantic-aware search that’s more accurate than text-based grep.The name of the symbol to find references for (e.g., “MyFunction”, “myVariable”, “MyType”)
Optional path to narrow the search to a specific directory or file. Defaults to the current directory.
Features
- Semantic search - Finds actual code references, not just string matches
- Language-aware - Works across multiple programming languages via LSP
- Precise results - Excludes comments and unrelated strings
- Location details - Returns file paths with exact line and column numbers
- Grouped output - Results organized by file for easy navigation
Usage
Find All References to a Function
HandleRequest is called or referenced.
Find References in a Specific Directory
internal/config directory.
Find References Using Qualified Names
Output Format
References are grouped by file with line and column information:When to Use
Use the References tool when you need to:- Find all usages of a function or variable
- Understand where a type is instantiated
- Identify dependencies before refactoring
- Track down all call sites for a method
- Understand code flow and usage patterns
Comparison with Other Tools
| Tool | Best For | Limitations |
|---|---|---|
| References | Finding symbol usages | Requires LSP server |
| Grep | Text pattern search | Finds string matches, not semantic references |
| Glob | File name search | Only finds files, not code references |
Limitations
- Results depend on LSP server capabilities and indexing
- May not find references in files not indexed by LSP
- Some LSP servers have better reference support than others
- Requires the LSP server to have indexed the codebase
Tips
- Use qualified names (e.g.,
pkg.Func,Class.method) for higher precision - Narrow scope with the path parameter for faster results
- Ensure your LSP server is running and has indexed your project
- For cross-language references, configure multiple LSP servers
- Use this before refactoring to understand impact
Common Patterns
Refactoring Preparation
Before renaming a function:- Use References to find all call sites
- Review each usage for compatibility
- Use Edit or MultiEdit to update call sites
- Run Diagnostics to verify changes
Understanding Code Flow
To understand how a function is used:- Use References to find all call sites
- Use View to examine each caller
- Build a mental model of the flow
- Document findings or refactor as needed
See Also
- LSP Configuration - Configure LSP servers
- Diagnostics Tool - Get code diagnostics
- Grep Tool - Text-based search
- Edit Tool - Make code changes