Add Comments to Selected Code
================================

The **Add Comment to the Selected Code** :ref:`predefined blueprint <key-term-blueprints>`  allows the insertion of LLM-generated, context-aware documentation into your code.

To use this feature, place the cursor on an element declaration (e.g., ``module``, ``interface``, ``class``, ``entity``) or select a piece of code, then either:

- Right-click and choose :menuselection:`AI Assistant --> Add Comment to the Selected Code`, or
- Use the command palette to run: :menuselection:`DVT AI: Start Session from Blueprint --> Add Comment to the Selected Code`

The response is shown in a side-by-side compare editor, highlighting the generated content.

.. note::

    The generated comments use the same markup language set for the editor tooltips (e.g., **Markdown**, **Javadoc**, **Natural Docs**).

Customization
-------------

Use the command :menuselection:`DVT AI: Edit Predefined Blueprint` to modify the blueprint.

The blueprint sends a set of predefined comments as reference for the LLM using the **@comments of element** snippet.

To modify the default snippet run the command :menuselection:`DVT AI: Edit Predefined Snippet`.

This action will extract several files under the ``.dvt/ai/snippets/comment-examples`` directory.

Each file corresponds to a specific element type and supported markup language (e.g., ``module_markdown.example``). You can directly modify the contents of these files with your own comments.


.. admonition:: Previewing the HTML Output

    You can preview the HTML version of your generated comments using |specador-live-preview|.

    .. figure:: ../../../images/common/specador_ai_assistant_preview.png
        :align: center

