Gemini-powered inline code completion — multi-line, context-aware suggestions that live inside your editor.
Topics: vscode-extension · developer-tools · code-autocomplete · gemini · generative-ai · google-ai · ide-integration · large-language-models · typescript · context-aware-suggestions
This VS Code extension integrates Google Gemini's code generation API directly into the editor's completion system, providing ghost-text inline suggestions as you type. Unlike standalone AI tools, it operates entirely within the developer's existing workflow — no context switching, no browser tab, no copy-pasting.
The extension captures the current file's language, the code before and after the cursor (up to a configurable context window), and sends it to the Gemini API in a structured completion prompt. The returned suggestion is rendered as greyed-out inline text; pressing Tab accepts it, Escape dismisses it. The extension supports configurable trigger modes: on-type (debounced), on explicit keyboard shortcut, or on file save.
Beyond completions, the extension provides a Command Palette command for full function generation: place the cursor inside an empty function body and invoke 'Gemini: Complete Function' to receive a multi-line implementation. Docstring generation and inline code explanation are available as additional commands.
GitHub Copilot and similar tools have demonstrated that inline AI completions dramatically improve developer productivity. However, they are tied to proprietary backends and subscription models. This extension provides an open, self-configurable alternative using Google's Gemini API — allowing developers to use their own API key with full control over the model, context length, and trigger behaviour.
Editor buffer change event
│
Context extraction (pre-cursor + post-cursor, language)
│
Gemini API call (chat/completions endpoint)
│
InlineCompletionItem injection into VS Code
│
Ghost text rendering (Tab=accept, Esc=dismiss)
Renders AI-generated code suggestions as greyed-out inline text directly in the editor buffer, accepted with Tab and dismissed with Escape — matching the UX of GitHub Copilot.
Works across Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, Ruby, SQL, and any language with a VS Code grammar — the model infers language from the file extension.
Send up to 8,000 tokens of surrounding code to the model for accurate, contextually relevant suggestions; configurable in VS Code Settings.
Invoke 'Gemini: Complete Function' from the Command Palette to generate a full function body from the signature and docstring alone.
Select a function signature and invoke 'Gemini: Generate Docstring' to insert a formatted docstring (Google, NumPy, or Sphinx style, configurable).
Hover over any selected code block and invoke 'Gemini: Explain Selection' to receive a plain-language explanation in the editor tooltip.
Choose between on-type (with configurable debounce delay), on-demand (keyboard shortcut only), or on-save trigger modes via Settings.
API key is stored in VS Code's SecretStorage (encrypted) rather than in settings.json, preventing accidental exposure in version control.
| Library / Tool | Role | Why This Choice |
|---|---|---|
| TypeScript | Extension language | VS Code extensions require TypeScript or JavaScript |
| VS Code Extension API | Editor integration | InlineCompletionProvider, SecretStorage, Commands |
| @google/generative-ai SDK | Gemini API client | Official Google Generative AI Node.js SDK |
| esbuild | Bundler | Fast TypeScript bundling for extension packaging |
| vscode-test | Testing framework | Extension integration test runner |
Key packages detected in this repo:
node-fetch
- Python 3.9+ (or Node.js 18+ for TypeScript/JS projects)
pipornpmpackage manager- Relevant API keys (see Configuration section)
git clone https://github.com/Devanik21/Gemini-Autocomplete-vscode.git
cd Gemini-Autocomplete-vscode
npm install
# Development mode (opens Extension Development Host)
npm run watch # in one terminal
# Press F5 in VS Code to launch
# Build VSIX for distribution
npm run package
code --install-extension gemini-autocomplete-*.vsix// Configure in VS Code Settings (settings.json)
{
"geminiAutocomplete.apiKey": "", // Set via command: Gemini: Set API Key
"geminiAutocomplete.triggerMode": "onType",
"geminiAutocomplete.debounceMs": 400,
"geminiAutocomplete.contextTokens": 2048,
"geminiAutocomplete.model": "gemini-2.0-flash"
}| Variable | Default | Description |
|---|---|---|
geminiAutocomplete.apiKey |
(empty) |
Google Gemini API key (set via SecretStorage command) |
geminiAutocomplete.model |
gemini-2.0-flash |
Gemini model ID for completions |
geminiAutocomplete.triggerMode |
onType |
Completion trigger: onType, onDemand, onSave |
geminiAutocomplete.debounceMs |
400 |
Milliseconds to wait after typing before triggering |
geminiAutocomplete.contextTokens |
2048 |
Tokens of surrounding code sent as context |
Copy
.env.exampleto.envand populate all required values before running.
Gemini-Autocomplete-vscode/
├── README.md
├── package-lock.json
├── package.json
├── tsconfig.json
└── ...
- Chat panel sidebar for multi-turn coding assistance without leaving the editor
- Repository-level context: index the entire workspace for more accurate project-aware completions
- Test generation command: generate unit tests from selected function implementations
- Diff view for multi-file refactoring suggestions
- Local model support via Ollama API for fully offline operation
Contributions, issues, and feature requests are welcome. Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'feat: add your feature') - Push to your branch (
git push origin feature/your-feature) - Open a Pull Request
Please follow conventional commit messages and ensure any new code is documented.
A valid Google Gemini API key is required. Free tier API keys have rate limits that may affect completion latency during intensive coding sessions. The extension does not transmit any code unless the completion trigger fires.
Devanik Debnath
B.Tech, Electronics & Communication Engineering
National Institute of Technology Agartala
This project is open source and available under the MIT License.
Crafted with curiosity, precision, and a belief that good software is worth building well.