Generate docstrings/comments for selected code using an OpenAI-compatible Chat Completions API, then watch the result stream directly into your file in real time.
- Streaming output: tokens appear word-by-word in the editor as they are generated — no waiting for the full response
- Auto-detect enclosing block: place the cursor anywhere inside a function or class — no manual selection needed
- Docstring style picker: choose Google, NumPy, reStructuredText, or auto style (Python only)
- Generate docstrings from selection: select any code block and run Generate Docstring
- Provider-agnostic: works with any service that supports
POST /chat/completionsin an OpenAI-compatible format - Cancelable requests: cancel from the progress notification to abort mid-stream
- Context menu integration: right-click on a selection → Generate Docstring
This repo is a VS Code extension project.
- Install dependencies:
npm install- Build once:
npm run compile- Run the extension:
- In VS Code, press
F5(orfn+F5on macOS) to open an Extension Development Host - In the dev host, open a file and run Generate Docstring
- Optional: select a function or class in the editor. If nothing is selected, the extension automatically detects the enclosing function/class at the cursor.
- Run AI Docstring Generator: Generate Docstring from:
- Keyboard shortcut:
Cmd+Shift+D(macOS) /Ctrl+Shift+D(Windows/Linux) - Command Palette (
Cmd/Ctrl+Shift+P) → search "Generate Docstring" - Editor right-click menu (only shows when there is a selection)
- Keyboard shortcut:
- Watch the docstring stream in above the selected code in real time.
Settings live under aiDocstringGenerator (VS Code Settings UI: search "AI Docstring Generator").
aiDocstringGenerator.apiKey: API key for your provider
-
aiDocstringGenerator.apiBaseUrl: base URL for an OpenAI-compatible API (default:https://api.openai.com/v1) -
aiDocstringGenerator.model: model name (provider-specific) -
aiDocstringGenerator.temperature: sampling temperature (default:0.2) -
aiDocstringGenerator.maxTokens: max tokens for the generated docstring (default:512; increase to1024+for complex classes or modules) -
aiDocstringGenerator.docstringStyle: docstring format style (default:auto)Value Description autoModel follows language conventions automatically googleGoogle Style — Args:,Returns:,Raises:sections (Python only)numpyNumPy/SciPy Style — Parameters\n----------,Returns\n-------(Python only)restreStructuredText / Sphinx — :param:,:type:,:returns:,:rtype:(Python only)Style variants only affect Python files. All other languages always use
auto.
aiDocstringGenerator.apiBaseUrl:https://api.openai.com/v1aiDocstringGenerator.model: e.g.gpt-4o-mini
Gemini offers an OpenAI-compatible endpoint.
aiDocstringGenerator.apiBaseUrl:https://generativelanguage.googleapis.com/v1beta/openai/aiDocstringGenerator.model: e.g.gemini-3-flash(choose a model supported by the compatibility layer)
ai-docstring-generator.generateDocstring: Generate Docstring
src/extension.ts: command registration, editor integration, streaming insertion, and block auto-detectionsrc/openaiCompat.ts: OpenAI-compatible client (streaming + non-streaming) + settings loadersrc/docstring.ts: prompt/messages builder with docstring style supportesbuild.js: bundles the extension todist/extension.js
npm run compile: typecheck + lint + bundlenpm run watch: watch mode (tsc + esbuild)npm test: run extension testsnpm run vsce:package: package the extension into a.vsixfilenpm run vsce:publish: publish to the VS Code Marketplace
- Do not commit API keys. Use VS Code settings for
aiDocstringGenerator.apiKey. - If you accidentally expose a key: revoke/regenerate it immediately.