Documenting code
watsonx Code Assistant
Generate comment lines that document what your code does.
Language support and standards
The following table lists code languages and the corresponding documentation standard for each code language.
Code | Documentation standard |
---|---|
C | doxygen |
C++ | doxygen |
Go | GoDoc |
Java | Javadoc |
JavaScript | JSDoc |
TypeScript | JSDoc |
All others | Markdown |
Using a chat command to generate documentation
You can use the /document
command in chat to generate documentation for a referenced file or a method or a class in the active workspace.
Use this syntax:
/document <code reference> [additional instructions]
For <code reference>
, type the @
symbol to see a list of files, classes, and methods from your workspace. Use one file, method, class reference at a time.
The [additional instructions]
are optional. Add instructions if you want specific details.
Examples prompts:
/document @file.java
/document @method1
Using the CodeLens in the editor to generate documentation
In the IDE editor, the CodeLens shows a line of generative AI options that precedes code blocks and snippets.
-
Click the Document option that immediately precedes a code block or snippet to generate its documentation.
In the following code example, the
Explain | Document | Unit Test
options immediately precede theprotected void
keywords.CodeLens example -
The watsonx Code Assistant chat window opens, displays the
/document @<*item name*>
command, runs the command, and displays the code with documentation added as comments.