DTA (Documentation,Unit Test generation, and Analysis) is a VS Code extension that uses IBM watsonx.ai and the Granite Code model to automatically generate comprehensive documentation, unit tests, and bug analysis for your code.
- Automatically generates comprehensive inline documentation for your code
- Supports 13+ programming languages (JavaScript, TypeScript, Python, Java, Go, C++, C#, Ruby, PHP, Rust, Swift, Kotlin, and more)
- Uses language-specific documentation formats (JSDoc, docstrings, JavaDoc, etc.)
- Shows a diff editor to review changes before applying
- Configurable output: replace original file or create separate .documented file
- Powered by IBM's Granite Code models
- Automatically generates comprehensive unit test suites for your code
- Detects and uses the appropriate test framework for each language:
- JavaScript/TypeScript → Jest
- Python → pytest
- Java/Kotlin → JUnit 5
- Go → Go testing package
- C++ → Google Test
- C# → xUnit
- And more...
- Generates tests with:
- Happy path test cases
- Edge cases and boundary conditions
- Error handling tests
- Mocked dependencies
- Clear, descriptive test names
- Creates test files following language conventions:
*.test.jsfor JavaScripttest_*.pyfor Python*Test.javafor Java*_test.gofor Go- And more...
- Opens test file side-by-side with source code
- AI-powered bug detection and code analysis
- Detects logic errors, null references, security vulnerabilities, performance issues, and more
- Configurable display modes:
- Inline comments: Add bug comments directly in code at problematic lines
- Diagnostics panel: Show bugs in VS Code's Problems panel with navigation
- Both: Combine inline comments and panel view
- Severity levels: error, warning, info
- Includes suggestions for fixing detected issues
- API key authentication with IBM Cloud IAM
- Secure token storage using VS Code's SecretStorage API
- Automatic token refresh (tokens expire after 1 hour)
- Easy login/logout from the status bar
- Status bar indicator showing connection status
- Editor toolbar buttons for quick access
- Visual diff editor to review generated documentation
- Side-by-side view for generated tests
- Integrated diagnostics for bug analysis
- Clear error messages and notifications
Before using DTA, you need:
- IBM Cloud Account: Sign up at cloud.ibm.com
- IBM Cloud API Key: For authentication with IBM Cloud IAM
- WatsonX Project ID: From IBM watsonx.ai
- Node.js 20+: For development
-
Clone or download this repository
-
Open the project in VS Code
-
Install dependencies:
npm install
-
Create a
.envfile in the project root (copy from.env.example):cp .env.example .env
-
Edit
.envand add your IBM Cloud credentials:WATSONX_PROJECT_ID=your_project_id_here WATSONX_REGION=us-south WATSONX_MODEL=ibm/granite-8b-code-instruct
-
Compile the extension:
npm run compile
-
Press F5 to launch the Extension Development Host
- Go to cloud.ibm.com/registration
- Sign up for a free account
- Go to IBM Cloud IAM API Keys
- Click "Create an IBM Cloud API key"
- Give it a name (e.g., DTA Extension")
- Copy the API key immediately (you won't be able to see it again)
- Store it securely - you'll use it to authenticate in VS Code
- Go to IBM watsonx.ai
- Create or select a project
- Go to project settings
- Copy the Project ID
- Open VS Code with the
- DTA extension installed
- Look at the status bar (bottom left) - you'll see "WatsonX: Not logged in"
- Click the status bar item or run command:
WatsonX: Login with IBM Cloud - Enter your IBM Cloud API key when prompted
- The extension will authenticate and you should see "WatsonX: Connected" in the status bar
- Open any code file (JavaScript, TypeScript, Python, Java, Go, C++, C#, etc.)
- Click the "Generate Docs" button in the editor toolbar (top right)
- Or use Command Palette:
WatsonX: Generate Documentation
- Or use Command Palette:
- Wait for the AI to generate documentation (usually 10-30 seconds)
- Review the changes in the diff editor
- Click "Apply Changes" to replace the original file, or "Save as New File" to create a .documented file
- Configure output mode in settings:
watsonx.docsOutputMode
- Configure output mode in settings:
Before:
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}After:
/**
* Calculates the total price of all items in the array
* @param {Array<{price: number}>} items - Array of items with price property
* @returns {number} The sum of all item prices
*/
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}- Open any code file you want to test
- Click the "Generate Tests" button in the editor toolbar (top right)
- Or use Command Palette:
WatsonX: Generate Tests
- Or use Command Palette:
- Wait for the AI to generate comprehensive tests (usually 15-45 seconds)
- The test file will be created and opened side-by-side with your source code
- Review and run the tests using your test framework
- Open any code file you want to analyze
- Click the "Analyze Bugs" button in the editor toolbar (top right)
- Or use Command Palette:
WatsonX: Analyze Bugs
- Or use Command Palette:
- Wait for the AI to analyze your code (usually 10-30 seconds)
- Based on your display mode setting:
- Inline mode: Review bug comments in diff editor, click "Apply Comments" to add them
- Panel mode: Check the Problems panel for detected bugs
- Both mode: See bugs in both locations
- Fix the detected issues and re-run analysis to verify
Code with Issues:
function calculateTotal(items) {
let total = 0;
for (let i = 0; i <= items.length; i++) { // Bug: off-by-one error
total += items[i];
}
return total;
}After Analysis (Inline Mode):
function calculateTotal(items) {
let total = 0;
// BUG: Off-by-one error - loop will access items[items.length] which is undefined
// Suggestion: Change <= to < in the loop condition
for (let i = 0; i <= items.length; i++) {
total += items[i];
}
return total;
}Source Code (calculator.js):
function add(a, b) {
return a + b;
}
function divide(a, b) {
if (b === 0) {
throw new Error('Cannot divide by zero');
}
return a / b;
}Generated Tests (calculator.test.js):
const { add, divide } = require('./calculator');
describe('Calculator Functions', () => {
describe('add', () => {
test('should add two positive numbers', () => {
expect(add(2, 3)).toBe(5);
});
test('should add negative numbers', () => {
expect(add(-2, -3)).toBe(-5);
});
test('should handle zero', () => {
expect(add(0, 5)).toBe(5);
});
});
describe('divide', () => {
test('should divide two numbers', () => {
expect(divide(10, 2)).toBe(5);
});
test('should throw error when dividing by zero', () => {
expect(() => divide(10, 0)).toThrow('Cannot divide by zero');
});
test('should handle negative numbers', () => {
expect(divide(-10, 2)).toBe(-5);
});
});
});The extension automatically creates test files following language-specific conventions:
| Language | Source File | Test File |
|---|---|---|
| JavaScript | app.js |
app.test.js |
| TypeScript | utils.ts |
utils.test.ts |
| Python | calculator.py |
test_calculator.py |
| Java | Calculator.java |
CalculatorTest.java |
| Go | handler.go |
handler_test.go |
| C++ | math.cpp |
math_test.cpp |
| C# | Service.cs |
ServiceTests.cs |
| Ruby | parser.rb |
parser_spec.rb |
Access these commands via Command Palette (Ctrl+Shift+P / Cmd+Shift+P):
WatsonX: Login with IBM Cloud- Authenticate with IBM Cloud using API keyWatsonX: Logout- Clear stored credentialsWatsonX: Generate Documentation- Generate docs for active fileWatsonX: Generate Tests- Generate unit tests for active fileWatsonX: Analyze Bugs- Analyze code for potential bugs and issues
Configure the extension via VS Code Settings (File > Preferences > Settings > Extensions > WatsonX):
| Setting | Type | Default | Description |
|---|---|---|---|
watsonx.projectId |
string | "" | IBM watsonx Project ID |
watsonx.region |
enum | "us-south" | IBM Cloud region (us-south, eu-de, jp-tok) |
watsonx.model |
string | "ibm/granite-8b-code-instruct" | WatsonX model to use |
watsonx.bugDisplayMode |
enum | "both" | How to display bugs (inline, panel, both) |
watsonx.docsOutputMode |
enum | "replace" | Documentation output (replace, newFile) |
| Language | Documentation Format | Test Framework |
|---|---|---|
| JavaScript | JSDoc | Jest |
| TypeScript | JSDoc | Jest |
| Python | Docstrings | pytest |
| Java | JavaDoc | JUnit 5 |
| Go | Go doc comments | Go testing |
| C++ | Doxygen | Google Test |
| C | Doxygen | Unity Test |
| C# | XML documentation | xUnit |
| Ruby | RDoc | RSpec |
| PHP | PHPDoc | PHPUnit |
| Rust | Rust doc comments | Rust test |
| Swift | Swift doc comments | XCTest |
| Kotlin | KDoc | JUnit 5 |
Solution: Click the status bar item or run WatsonX: Login with IBM Cloud
Solution: Check that your .env file has all required credentials
Solution: The extension auto-refreshes tokens. If it fails, log out and log in again.
Solution: Wait a few minutes before making more requests
Solution: Check your internet connection and IBM Cloud status
Solution: Ensure your API key is valid and has access to watsonx.ai. Check the Output panel for detailed error messages.
dta/
├── src/
│ ├── extension.ts # Main entry point
│ ├── auth/
│ │ ├── ibmAuth.ts # OAuth orchestration
│ │ ├── callbackServer.ts # Local OAuth server
│ │ └── tokenManager.ts # Token management
│ ├── watsonx/
│ │ ├── apiClient.ts # WatsonX API client
│ │ ├── prompts.ts # Prompt templates
│ │ └── types.ts # TypeScript interfaces
│ ├── features/
│ │ ├── generateDocs.ts # Documentation feature
│ │ ├── generateTests.ts # Test generation feature
│ │ └── analyzeBugs.ts # Bug analysis feature
│ ├── ui/
│ │ └── statusBar.ts # Status bar component
│ └── utils/
│ ├── config.ts # Configuration
│ └── logger.ts # Logging
├── .env # Your credentials (gitignored)
├── .env.example # Template
├── package.json # Extension manifest
└── tsconfig.json # TypeScript config
npm run compile # Compile TypeScript
npm run watch # Watch mode for development
npm run package # Create .vsix package
npm test # Run tests- Open project in VS Code
- Press F5 to launch Extension Development Host
- Set breakpoints in TypeScript files
- Check Output panel > WatsonX for logs
- Support for more languages
- Custom prompt templates
- Batch documentation generation
- Integration with CI/CD pipelines
- API keys are stored securely using VS Code's SecretStorage API
- Tokens are encrypted and never logged
- All API calls use HTTPS
- No code is stored or transmitted except during API calls to IBM watsonx.ai
ISC
For issues, questions, or contributions:
- Check the Troubleshooting section
- Review the Output panel (View > Output > WatsonX)
- Open an issue on the repository
Built with:
- IBM watsonx.ai and Granite Code models
- VS Code Extension API
- TypeScript
- Express.js for local callback server
Made with Bob