Zencoder’s AI-powered documentation capabilities help you create clear, professional documentation at multiple levels of your codebase. From detailed docstrings for individual functions to comprehensive documentation for entire modules or projects, Zencoder ensures your code is well-documented and maintainable.

Docstring Generation

Docstrings are the foundation of good code documentation, providing detailed information about functions, methods, and classes directly in the code. Zencoder excels at generating accurate and comprehensive docstrings by analyzing your code’s logic and structure.

How to Generate Docstrings

There are several ways to generate docstrings with Zencoder. Here’s a step-by-step guide on how to do so with Code Lenses or directly in the chat.

Using Code Lenses

1

Locate the Code Lens

Look for the code lens that appears above your class, method, or function

2

Select the Add Doc Comments Option

Click on the code lens and select “Add doc comments” from the menu

3

Review the Generated Docstring

Zencoder will automatically generate and insert appropriate docstrings directly into your code

Alternative Methods

Sometimes code lenses might not be visible or might not be your preferred way of working. In these cases, you can also generate docstrings through the chat interface:

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 like Generate docstring with best practices into the chat, then hit submit

4

Apply the Generated Docstring

Zencoder will provide a comprehensive docstring including:

  • Function/method purpose
  • Parameter descriptions with types
  • Return value details
  • Exception information when applicable

Copy and paste the generated docstring into your code

You can also use custom prompts to generate docstrings in specific formats or following particular standards. For example: “Generate PEP 257 compliant docstrings” or “Create JSDoc style documentation for this function.”

Example: Before and After

Here’s a concise example of how Zencoder transforms undocumented code with clear, professional 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

While docstrings provide documentation at the function and class level, Zencoder can also generate comprehensive documentation for entire files, modules, or projects. This is particularly useful for creating README files, API documentation, or user guides.

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 Generated Content

Zencoder provides:

  • A concise explanation of the code’s purpose
  • Detailed descriptions of components, parameters, outputs, and usage
  • Example use cases for added clarity
5

Make Refinements

Review the generated documentation and make any necessary refinements to match your specific needs

Best Practices

For the best results with Zencoder’s documentation features:

  1. Be specific in your prompts - The more specific your request, the more tailored the documentation will be
  2. Include context - When generating docstrings, include enough of the surrounding code for Zencoder to understand the context
  3. Iterate when needed - For complex code, you might need to refine the documentation through a few iterations
  4. Standardize your approach - Establish documentation standards for your team and include them in your prompts

Remember that while Zencoder generates excellent documentation, it’s always good practice to review and adjust the output to ensure it perfectly matches your project’s needs and standards.