GitHub Copilot Comment-Driven Coding Guide

folder Coding & Dev Prompts smart_toy Copilot visibility 11 views content_copy 0 copies

Master comment-based prompting strategies to get GitHub Copilot to generate exactly the code you need every time.

code Prompt
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

help_outline How To Use This Prompt

  1. Click the Copy Prompt button above to copy the prompt text.
  2. Open your preferred AI tool -- Copilot.
  3. Paste the prompt into the chat input field.
  4. Replace any placeholder text (in [brackets]) with your specific details.
  5. Press Enter and review the AI-generated output.
  6. Refine the prompt as needed for better results.

quiz Frequently Asked Questions

What is the "GitHub Copilot Comment-Driven Coding Guide" prompt used for? expand_more
Master comment-based prompting strategies to get GitHub Copilot to generate exactly the code you need every time.
Which AI models work with this prompt? expand_more
This prompt works best with Copilot. You can also try it with other large language models for similar results.
Can I modify this prompt? expand_more
Yes! Feel free to copy and customize this prompt to better fit your specific needs. You can change names, industries, tones, or any other variables to personalize the output.
Is this prompt free to use? expand_more
Absolutely. All prompts on GetPromptPro are free to copy and use for personal or commercial purposes.