| description | applyTo |
|---|---|
You are an expert at using C++ language service tools (GetSymbolReferences_CppTools, GetSymbolInfo_CppTools, GetSymbolCallHierarchy_CppTools). Instructions for calling C++ Tools for Copilot. When working with C++ code, you have access to powerful language service tools that provide accurate, IntelliSense-powered analysis. **Always prefer these tools over manual code inspection, text search, or guessing.** |
**/*.cpp, **/*.h, **/*.hpp, **/*.cc, **/*.cxx, **/*.c |
You have access to three specialized C++ tools:
GetSymbolInfo_CppTools- Find symbol definitions and get type detailsGetSymbolReferences_CppTools- Find ALL references to a symbolGetSymbolCallHierarchy_CppTools- Analyze function call relationships
NEVER rely on manual code inspection, vscode_listCodeUsages, grep_search, or read_file to find where a symbol is used.
ALWAYS call GetSymbolReferences_CppTools when:
- Renaming any symbol (function, variable, class, method, etc.)
- Changing function signatures
- Refactoring code
- Understanding symbol impact
- Finding all call sites
- Identifying usage patterns
- Any task involving "find all uses/usages/references/calls"
Why: GetSymbolReferences_CppTools uses C++ IntelliSense and understands:
- Overloaded functions
- Template instantiations
- Qualified vs unqualified names
- Member function calls
- Inherited member usage
- Preprocessor-conditional code
Text search tools will miss these or produce false positives.
Before modifying any function signature, ALWAYS call GetSymbolCallHierarchy_CppTools with callsFrom=false to find all callers.
Examples:
- Adding/removing function parameters
- Changing parameter types
- Changing return types
- Making functions virtual
- Converting to template functions
Why: This ensures you update ALL call sites, not just the ones you can see.
Before working with unfamiliar code, ALWAYS call GetSymbolInfo_CppTools to:
- Find where a symbol is defined
- Understand class/struct memory layout
- Get type information
- Locate declarations
NEVER assume you know what a symbol is without checking.
- ALWAYS REQUIRED: Provide the symbol name
- Can be unqualified (
MyFunction), partially qualified (MyClass::MyMethod), or fully qualified (MyNamespace::MyClass::MyMethod) - If you have a line number, the symbol should match what appears on that line
- STRONGLY PREFERRED: Always provide absolute file paths when available
- ✅ Good:
C:\Users\Project\src\main.cpp - ❌ Avoid:
src\main.cpp(requires resolution, may fail)
- ✅ Good:
- If you have access to a file path, include it
- If working with user-specified files, use their exact path
- CRITICAL: Line numbers are 1-based, NOT 0-based
- MANDATORY WORKFLOW when you need a line number:
- First call
read_fileto search for the symbol - Locate the symbol in the output
- Note the EXACT line number from the output
- VERIFY the line contains the symbol
- Only then call the C++ tool with that line number
- First call
- NEVER guess or estimate line numbers
- If you don't have a line number, omit it - the tools will find the symbol
Start with minimal information and add more only if needed:
- First attempt: Symbol name only
- If ambiguous: Symbol name + file path
- If still ambiguous: Symbol name + file path + line number (after using
read_file)
CORRECT workflow:
1. Call GetSymbolReferences_CppTools with symbol name (and file path if available)
2. Review ALL references returned
3. Update symbol at definition location
4. Update symbol at ALL reference locations
INCORRECT workflow:
❌ Using vscode_listCodeUsages or grep_search to find usages
❌ Manually inspecting a few files
❌ Assuming you know all the usages
CORRECT workflow:
1. Call GetSymbolInfo_CppTools to locate the function definition
2. Call GetSymbolCallHierarchy_CppTools with callsFrom=false to find all callers
3. Call GetSymbolReferences_CppTools to catch any additional references (function pointers, etc.)
4. Update function definition
5. Update ALL call sites with new signature
INCORRECT workflow:
❌ Changing the function without finding callers
❌ Only updating visible call sites
❌ Using text search to find calls
CORRECT workflow:
1. Call GetSymbolInfo_CppTools on key types/functions to understand definitions
3. Call GetSymbolCallHierarchy_CppTools with callsFrom=true to understand what a function does
4. Call GetSymbolCallHierarchy_CppTools with callsFrom=false to understand where a function is used
INCORRECT workflow:
❌ Reading code manually without tool assistance
❌ Making assumptions about symbol meanings
❌ Skipping hierarchy analysis
CORRECT workflow:
1. Call GetSymbolCallHierarchy_CppTools with callsFrom=true to see what the function calls (outgoing)
2. Call GetSymbolCallHierarchy_CppTools with callsFrom=false to see what calls the function (incoming)
3. Use this to understand code flow and dependencies
INCORRECT workflow:
❌ Manually reading through function body
❌ Guessing at call patterns
All error messages contain specific recovery instructions. ALWAYS follow them exactly.
Error: "The symbol name is not valid: it is either empty or null. Find a valid symbol name. Then call the [tool] tool again"
Recovery:
1. Ensure you provided a non-empty symbol name
2. Check that the symbol name is spelled correctly
3. Retry with valid symbol name
Error: "A file could not be found at the specified path. Compute the absolute path to the file. Then call the [tool] tool again."
Recovery:
1. Convert relative path to absolute path
2. Verify file exists in the workspace
3. Use exact path from user or file system
4. Retry with absolute path
Message: "No results found for the symbol '[symbol_name]'."
This is NOT an error - it means:
- The symbol exists and was found
- But it has no references/calls/hierarchy (depending on tool)
- This is valid information - report it to the user
Question: Do I need to find where a symbol is used/called/referenced?
- ✅ YES → Use
GetSymbolReferences_CppTools - ❌ NO → Continue
Question: Am I changing a function signature or analyzing function calls?
- ✅ YES → Use
GetSymbolCallHierarchy_CppTools- Finding callers? →
callsFrom=false - Finding what it calls? →
callsFrom=true
- Finding callers? →
- ❌ NO → Continue
Question: Do I need to find a definition or understand a type?
- ✅ YES → Use
GetSymbolInfo_CppTools - ❌ NO → You may not need a C++ tool for this task
- ✅ Call
GetSymbolReferences_CppToolsfor ANY symbol usage search - ✅ Call
GetSymbolCallHierarchy_CppToolsbefore function signature changes - ✅ Use
read_fileto find line numbers before specifying them - ✅ Provide absolute file paths when available
- ✅ Follow error message instructions exactly
- ✅ Trust tool results over manual inspection
- ✅ Use minimal parameters first, add more if needed
- ✅ Remember line numbers are 1-based
- ❌ Use
vscode_listCodeUsages,grep_search, orread_fileto find symbol usages - ❌ Manually inspect code to find references
- ❌ Guess line numbers
- ❌ Assume symbol uniqueness without checking
- ❌ Ignore error messages
- ❌ Skip tool usage to save time
- ❌ Use 0-based line numbers
- ❌ Batch multiple unrelated symbol operations
- ❌ Make changes without finding all affected locations
User: "Rename the function ProcessData to HandleData"
CORRECT response:
1. Call GetSymbolReferences_CppTools("ProcessData")
2. Review all reference locations
3. Update function definition
4. Update all call sites shown in results
5. Confirm all changes made
INCORRECT response:
❌ Using grep_search to find "ProcessData"
❌ Only updating files the user mentioned
❌ Assuming you found all usages manually
User: "Add a parameter 'bool verbose' to the LogMessage function"
CORRECT response:
1. Call GetSymbolInfo_CppTools("LogMessage") to find definition
2. Call GetSymbolCallHierarchy_CppTools("LogMessage", callsFrom=false) to find all callers
3. Call GetSymbolReferences_CppTools("LogMessage") to catch any function pointer uses
4. Update function definition
5. Update ALL call sites with new parameter
INCORRECT response:
❌ Only updating the definition
❌ Updating only obvious call sites
❌ Not using call_hierarchy tool
User: "What does the Initialize function do?"
CORRECT response:
1. Call GetSymbolInfo_CppTools("Initialize") to find definition and location
2. Call GetSymbolCallHierarchy_CppTools("Initialize", callsFrom=true) to see what it calls
3. Read the function implementation
4. Explain based on code + call hierarchy
INCORRECT response:
❌ Only reading the function body
❌ Not checking what it calls
❌ Guessing at behavior
- Call tools in parallel when analyzing multiple independent symbols
- Use file paths to speed up symbol resolution
- Provide context to narrow searches
- If first tool call is ambiguous, add file path
- If still ambiguous, use
read_fileto find exact line - Tools are designed for iteration
- Empty results are valid: "No results found" means the symbol has no references/calls
- Multiple results are common: C++ has overloading, templates, namespaces
- Trust the tools: IntelliSense knows C++ semantics better than text search
- ONLY for finding line numbers before calling C++ tools
- ONLY for reading implementation details after locating symbols
- NEVER for finding symbol usages (use
GetSymbolReferences_CppToolsinstead)
- Finding string literals or comments
- Searching non-C++ files
- Pattern matching in configuration files
- NEVER for finding C++ symbol usages
- Finding code based on conceptual queries
- Locating relevant files in large codebases
- Understanding project structure
- Then use C++ tools for precise symbol analysis
The golden rule: When working with C++ code, think "tool first, manual inspection later."
- Symbol usages? →
GetSymbolReferences_CppTools - Function calls? →
GetSymbolCallHierarchy_CppTools - Symbol definition? →
GetSymbolInfo_CppTools
These tools are your primary interface to C++ code understanding. Use them liberally and often. They are fast, accurate, and understand C++ semantics that text search cannot capture.
Your success metric: Did I use the right C++ tool for every symbol-related task?