Master comment-based prompting strategies to get GitHub Copilot to generate exactly the code you need every time.
Use these structured comment templates to guide GitHub Copilot to produce accurate, production-quality code.
**Template 1 - New Function**
```
// Function: [functionName]
// Purpose: [what it does in plain English]
// Parameters: param1 (type): description, param2 (type): description
// Returns: type - what it returns and when
// Edge cases handled: null input, empty array, rate limit exceeded
// Example: functionName(input) returns expected output
function functionName(params) {
```
**Template 2 - API Integration**
```
// API call to [SERVICE] endpoint [PATH]
// Method: GET or POST or PUT or DELETE
// Authentication: Bearer token in Authorization header
// Request body: { field: type, field2: type }
// On success: returns { id, status, data }
// Handle errors: 401 unauthorized, 404 not found, 429 rate limited, 500 server error
// Retry strategy: exponential backoff on 503
async function fetchResource(params) {
```
**Template 3 - Database Query**
```
// Query: SELECT columns FROM table
// Join: LEFT JOIN table2 ON condition
// Filter: WHERE active = true AND created_at > cutoff date
// Order: BY created_at DESC
// Limit: 50 results
// Expected return shape: array of { id, name, email, created_at }
```
**Template 4 - React Component**
```
// Component: ComponentName
// Props: { userId: string, onComplete: function, isLoading: boolean }
// Local state: selected item, error message
// Side effects: fetch user data on mount, cleanup subscription on unmount
// Renders: header with title, list of items, submit button
```
**Key Rules for Better Copilot Output:**
- Specific beats vague: validates email format beats validates input
- Include example inputs and outputs in comments
- Specify error handling explicitly
- Mention performance constraints upfront