This page covers how to generate two types of documentation with Zencoder:
  1. Docstrings - In-code documentation for functions, classes, and methods (available via code lenses or direct prompting)
  2. Generic Documentation - README files, API docs, and module documentation (available via prompting)
We’ll also cover best practices and troubleshooting for common issues.

Docstring Generation

Docstrings are structured comments embedded directly in your code that document functions, methods, and classes. They follow language-specific conventions (Python docstrings, JSDoc for JavaScript/TypeScript, PHPDoc for PHP, Javadoc for Java, etc.) and are used by IDEs for tooltips, API documentation generators, and code intelligence features. Unlike generic documentation that might live in separate files, docstrings stay with the code they describe.

How to Generate Docstrings

There are two methods to generate docstrings with Zencoder:
  1. Using Code Lenses - The fastest way to add documentation directly in your editor
  2. Direct Prompting - Generate docstrings and general documentation through the chat interface with custom requirements

Using Code Lenses

VS Code Code Lenses

When you open a file in VS Code, you’ll see a Zencoder code lens above your functions, classes, and methods.
1

Click the Zencoder Code Lens

Click on the Zencoder code lens that appears above your codeVS Code showing Zencoder code lens above functions
2

Select Add Doc Comments

From the dropdown menu, select Add doc comments
3

Review and Apply

Review the generated docstring and apply the changes

Direct Prompting

Generate docstrings through the chat interface when code lenses aren’t available or when you need more control:
1

Highlight Your Code

Highlight the code snippet or function you want to document
2

Send to Chat

Right-click and select Zencoder > Insert Selection into Chat or use Ctrl + L (Windows) / CMD + L (Mac) to copy the selection into the chat window
3

Request Docstring Generation

Type a prompt into the chat, then hit submit. For example:
Generate docstring with best practices
4

Apply the Generated Docstring

The generated docstring will include:
  • Function/method purpose
  • Parameter descriptions with types
  • Return value details
  • Exception information when applicable
Copy and paste the docstring into your code
Use specific prompts to match your project’s documentation standards:
Generate PEP 257 compliant docstrings
Create JSDoc style documentation for this function

Example: Before and After

Example of generated Python docstrings:
def fetch_user_data(user_id, include_history=False):
    data = database.get_user(user_id)
    if include_history:
        data['history'] = database.get_user_history(user_id)
    return data

def format_name(first, last, middle=None):
    if middle:
        return f"{last}, {first} {middle[0]}."
    return f"{last}, {first}"

Generic Documentation Generation

Generic documentation covers entire files, modules, or projects - things like README files, API documentation, architecture guides, and user manuals. This documentation lives in separate files rather than inline with code.

How to Generate Broader Documentation

1

Open Zencoder's Chat Window

Access Zencoder by opening the chat window in your IDE or web interface
2

Enable the Coding Agent

Toggle on the Coding Agent feature to give Zencoder more capabilities for comprehensive documentation generation
3

Enter Your Documentation Request

Type a clear prompt, such as:
Generate documentation for this file
Create a README for this project
Document the API in this module
4

Review and Apply

The generated documentation will include:
  • Code purpose and functionality
  • Component descriptions, parameters, and outputs
  • Usage examples where applicable
Review the output and apply or modify as needed.

Best Practices

  1. Be specific in your prompts - Include details about format, style guide, or specific requirements
  2. Provide context - Include surrounding code when generating docstrings for better accuracy
  3. Iterate as needed - Complex code may require refinement over multiple attempts
  4. Include your standards - Add team conventions or style guides to your prompts for consistency
Always review generated documentation before committing to ensure accuracy and compliance with your project standards.

Troubleshooting