Code To Doc
A Visual Studio Code extension that generates JSDoc comments for your JavaScript and TypeScript code using OpenAI's API. Enhance your codebase with clear, professional documentation automatically!
Features
- Generate JSDoc comments for selected code or the entire file.
- Works for functions, classes, and other code blocks.
- Seamless integration with OpenAI for high-quality documentation generation.
- Supports JavaScript and TypeScript.
- Securely store and manage your OpenAI API key.
Usage
1. Set OpenAI API Key
Before using the extension, you need to set your OpenAI API key:
- Open the Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
).
- Search for and run the command Set OpenAI API Key.
- Enter your OpenAI API key (e.g.,
sk-XXXX...
).
- The key is securely stored using VS Code's
SecretStorage
.
2. Generate Documentation
To generate documentation:
Select a Block of Code:
- Highlight the function, class, or code snippet you want to document.
- If nothing is selected, the extension will use the entire file.
Run the Command:
- Open the Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
).
- Search for and run the command Generate Documentation.
View the Output:
- The generated JSDoc comment will be inserted above the selected code or at the top of the file.
Example
function addNumbers(a, b) {
return a + b;
}
Output Code:
/**
* Adds two numbers together.
*
* @param {number} a - The first number to add.
* @param {number} b - The second number to add.
* @returns {number} The sum of the two numbers.
*
* @example
* // returns 5
* addNumbers(2, 3);
*
* @example
* // returns 10
* addNumbers(7, 3);
*/
function addNumbers(a, b) {
return a + b;
}
Requirements
- Node.js v16+
- An OpenAI API key (get one from OpenAI).
Extension Settings
This extension uses the following commands:
Set OpenAI API Key:
- Command:
codeToDoc.setApiKey
- Use this to store your OpenAI API key securely.
Generate Documentation:
- Command:
codeToDoc.generateDocumentation
- Use this to generate JSDoc comments.
Known Issues
- Limited support for non-JavaScript/TypeScript code.
- Requires an active OpenAI API key, which may incur usage costs.
Contributing
Contributions are welcome! If you’d like to contribute:
- Fork this repository.
- Create a new feature branch.
- Submit a pull request.
Support
If you encounter any issues or have questions, feel free to reach out via GitHub Issues or email.
License
This extension is licensed under the MIT License. See LICENSE
for more details.