Skip to main content
AIPromptIndex
GitHub Copilot Coding beginner

Copilot Code Comment Generator

Added Apr 2, 2026

You are a technical documentation specialist. Add comprehensive, meaningful comments to the following [LANGUAGE] code from a [PROJECT_TYPE] project. The code handles [FUNCTIONALITY]. [CODE_BLOCK] Apply these commenting standards: add a file-level docstring explaining the module's purpose and its role in the larger system, add JSDoc/docstring comments to every function and class with parameters, return types, exceptions thrown, and usage examples, add inline comments only where the code does something non-obvious or uses a workaround with a brief explanation of why, mark any technical debt or known limitations with TODO or FIXME comments, add section separator comments for logical code blocks within long functions, include complexity notes (Big O) for algorithms and data structure operations, and document any implicit assumptions or prerequisites. Do not add comments that merely restate what the code does in English. Every comment should add context, explain reasoning, or warn about gotchas that the code alone does not convey. Preserve all original code exactly as written.
0
Share
Try in GitHub Copilot

About This Prompt

This prompt adds professional-quality documentation comments to existing code without modifying the code itself. Good comments explain the why, not the what, and this prompt follows that principle by adding context about design decisions, complexity implications, known limitations, and non-obvious behavior. The output includes file-level documentation, function signatures with full parameter descriptions, strategic inline comments, and technical debt markers. This is particularly useful when onboarding new team members to a codebase, preparing code for open-source release, or retrofitting documentation into legacy code that lacks it.

Variables to Customize

[LANGUAGE]

The programming language

Example: Python

[PROJECT_TYPE]

Type of project

Example: Django REST API

[FUNCTIONALITY]

What this code does

Example: user permission checking and role-based access control

[CODE_BLOCK]

The code to add comments to

Example: # paste your code here

Tips for Best Results

  • Include the broader project context so comments can reference how this module fits into the system
  • Review generated comments and remove any that merely restate obvious code behavior
  • Use this as a starting point and add domain-specific context that only you know about

Example Output

"""
Permission Service - Role-Based Access Control (RBAC)

Central authorization layer for the API. All endpoint decorators
and middleware route through this module to verify user permissions.

Architecture note: Uses a hierarchical role model where admin > editor > viewer.
Permissions are cached per-request in the user object to avoid repeated DB queries.

See also: auth/models.py for Role definitions, middleware/auth.py for request integration.
"""

def check_permission(user: User, resource: str, action: str) -> bool:
    """
    Verify if a user has permission to perform an action on a resource.
    
    Args:
        user: Authenticated user object with .roles populated
        resource: Resource identifier (e.g., 'posts', 'users', 'settings')
        action: CRUD action ('create', 'read', 'update', 'delete')
    
    Returns:
        True if the user has sufficient permissions
    
    Raises:
        PermissionDenied: If user.roles is empty (indicates auth middleware was bypassed)
    
    Example:
        if check_permission(request.user, 'posts', 'delete'):
            post.delete()
    """
    # FIXME: Role cache is not invalidated when admin changes user roles mid-session
    ...
documentation code-comments jsdoc code-quality developer-experience

Get the Best AI Prompts Weekly

Curated prompts, tips, and guides delivered to your inbox every week. Free.