Code To Doc
A Visual Studio Code extension that generates JSDoc comments for your JavaScript and TypeScript code using Google Gemini'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 Google Gemini for high-quality documentation generation.
- Supports JavaScript and TypeScript.
- Securely store and manage your Gemini API key.
Usage
1. Set Gemini API Key
Before using the extension, you need to set your Google Gemini API key:
- Open the Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
).
- Search for and run the command Set Gemini API Key.
- Enter your Gemini API key (e.g.,
AIzaSy...
).
- 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
Extension Settings
This extension uses the following commands:
Set Gemini API Key:
- Command:
codeToDoc.setGeminiApiKey
- Use this to store your Gemini 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 Gemini API key, which may have usage limits.
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.