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 |
When you reference a method, or use CodeLens on a method, watsonx Code Assistant supports certain code languages. Referencing a full file works for all languages. For more information, see Language support when you work with methods.
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.
When you reference a file, the size limit is 50 KB. If you reach this limit, split the file into individual functions and reference each function. Or, split the file at 49 KB, taking care of function boundaries, and reference the file at each split. With either approach, you need to merge the results.
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.
Disabling CodeLens
If you want to disable the CodeLens options, you can change the setting for the extension or plug-in.
In Visual Studio Code:
-
Open the settings for the extension.
-
Clear the
Enable CodeLens
setting.
In Eclipse:
-
Open the settings for the Eclipse IDE.
-
In the watsonx Code Assistant Settings entry, clear the
Enable CodeLens
setting. -
Click Apply and close.