Skip to content

Devanik21/Gemini-Autocomplete-vscode

Repository files navigation

Gemini Autocomplete Vscode

Language Stars Forks Author Status

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

Overview

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.


Motivation

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.


Architecture

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)

Features

Ghost-Text Inline Completions

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.

Multi-Language Support

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.

Configurable Context Window

Send up to 8,000 tokens of surrounding code to the model for accurate, contextually relevant suggestions; configurable in VS Code Settings.

Function Completion Command

Invoke 'Gemini: Complete Function' from the Command Palette to generate a full function body from the signature and docstring alone.

Docstring Generator

Select a function signature and invoke 'Gemini: Generate Docstring' to insert a formatted docstring (Google, NumPy, or Sphinx style, configurable).

Inline Code Explanation

Hover over any selected code block and invoke 'Gemini: Explain Selection' to receive a plain-language explanation in the editor tooltip.

Trigger Mode Configuration

Choose between on-type (with configurable debounce delay), on-demand (keyboard shortcut only), or on-save trigger modes via Settings.

Secure API Key Management

API key is stored in VS Code's SecretStorage (encrypted) rather than in settings.json, preventing accidental exposure in version control.


Tech Stack

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


Getting Started

Prerequisites

  • Python 3.9+ (or Node.js 18+ for TypeScript/JS projects)
  • pip or npm package manager
  • Relevant API keys (see Configuration section)

Installation

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

Usage

// 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"
}

Configuration

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.example to .env and populate all required values before running.


Project Structure

Gemini-Autocomplete-vscode/
├── README.md
├── package-lock.json
├── package.json
├── tsconfig.json
└── ...

Roadmap

  • 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

Contributing

Contributions, issues, and feature requests are welcome. Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'feat: add your feature')
  4. Push to your branch (git push origin feature/your-feature)
  5. Open a Pull Request

Please follow conventional commit messages and ensure any new code is documented.


Notes

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.


Author

Devanik Debnath
B.Tech, Electronics & Communication Engineering
National Institute of Technology Agartala

GitHub LinkedIn


License

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.

About

VS Code extension with Gemini-powered ghost-text inline completions — context-aware multi-language suggestions, Tab/Esc UX, SecretStorage key management, and CoT commands.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors