AI Coding Agent - VS Code Extension
A powerful AI-powered coding assistant extension for Visual Studio Code that provides intelligent code suggestions, explanations, refactoring, and code reviews.
✨ Features
🤖 AI Chat Panel
- Interactive chat interface in the sidebar
- Ask questions about your code
- Get code generation assistance
- Receive explanations and suggestions
- Apply code directly to your editor
⚡ Inline Code Completions
- GitHub Copilot-style ghost text suggestions
- Context-aware completions
- Accept with
Tab, reject with Esc
- Configurable suggestion delay
🔄 Diff Preview
- Visual side-by-side comparison of original and AI-suggested code
- Accept, reject, or edit suggestions before applying
- Built-in VS Code diff editor integration
🛠️ Code Actions
- Explain Code: Get detailed explanations of selected code
- Refactor Code: Receive refactoring suggestions with diff preview
- Review Code: Get code quality reviews and best practice suggestions
- Right-click on selected code to access AI features
- Quick access to explain, refactor, and review commands
⌨️ Keyboard Shortcuts
Ctrl+Shift+A (Mac: Cmd+Shift+A) - Open AI Chat
Tab - Accept inline suggestion
Esc - Reject inline suggestion
🚀 Getting Started
Installation
- Clone this repository:
git clone <repository-url>
cd vscode-ai-agent
- Install dependencies:
npm install
- Compile the extension:
npm run compile
- Open in VS Code:
code .
- Press
F5 to launch the extension in a new VS Code window
Development
- Watch mode:
npm run watch - Automatically recompile on file changes
- Lint:
npm run lint - Check code quality
📖 Usage
Opening the Chat Panel
- Click the AI Agent icon in the Activity Bar (left sidebar)
- Or press
Ctrl+Shift+A (Mac: Cmd+Shift+A)
- Or use Command Palette:
AI Agent: Open Chat
Using Inline Completions
- Start typing code in any file
- Wait for ghost text suggestions to appear
- Press
Tab to accept or Esc to reject
Code Actions
- Select code in the editor
- Right-click to open context menu
- Choose from AI Agent options:
- ✨ AI: Explain this code
- 🔧 AI: Refactor this code
- 📋 AI: Review this code
Diff Preview Workflow
- Request a code modification (refactor, generate, etc.)
- Diff editor opens showing original vs. modified code
- Choose an action:
- ✓ Accept Changes - Apply to your file
- ✗ Reject Changes - Discard suggestion
- ✎ Edit Before Applying - Open in editor to modify
⚙️ Configuration
Access settings via File > Preferences > Settings and search for "AI Agent":
| Setting |
Default |
Description |
aiAgent.enabled |
true |
Enable/disable AI Agent features |
aiAgent.inlineCompletions |
true |
Enable inline code completions |
aiAgent.autoShowDiff |
true |
Automatically show diff preview for suggestions |
aiAgent.suggestionDelay |
500 |
Delay in milliseconds before showing suggestions |
🏗️ Architecture
Folder Structure
vscode-ai-agent/
├── src/
│ ├── extension.ts # Extension entry point
│ ├── commands/ # Command handlers
│ │ └── index.ts
│ ├── providers/ # VS Code providers
│ │ ├── inlineCompletionProvider.ts
│ │ └── codeActionProvider.ts
│ ├── webview/ # Webview controllers
│ │ ├── chatPanel.ts
│ │ └── diffPreview.ts
│ ├── statusBar/ # Status bar integration
│ │ └── aiStatusBar.ts
│ └── utils/ # Utilities
├── media/ # Static assets
│ ├── icons/
│ └── styles/
├── package.json # Extension manifest
└── tsconfig.json # TypeScript config
Key Components
Extension Entry Point (extension.ts)
- Activates the extension
- Registers all providers and commands
- Initializes status bar
Chat Panel (webview/chatPanel.ts)
- Webview-based chat interface
- Message handling between extension and UI
- Code application and diff preview triggers
Inline Completion Provider (providers/inlineCompletionProvider.ts)
- Provides ghost text suggestions
- Context-aware completions
- Configurable delay and behavior
Diff Preview (webview/diffPreview.ts)
- Uses VS Code's built-in diff editor
- Action handling (accept/reject/edit)
- Temporary document management
Code Action Provider (providers/codeActionProvider.ts)
- Quick fixes and refactoring suggestions
- Context menu integration
- Lightbulb actions
Status Bar (statusBar/aiStatusBar.ts)
- Shows AI agent status
- Click to open chat
- Visual feedback for AI operations
🔌 Backend Integration
This extension is designed as a frontend-only layer. To connect to an AI backend:
Locate TODO comments in the code:
src/webview/chatPanel.ts - handleUserMessage()
src/providers/inlineCompletionProvider.ts - getAISuggestion()
src/commands/index.ts - Various command handlers
Implement API calls to your AI service:
// Example integration
async function callAIBackend(prompt: string): Promise<string> {
const response = await fetch('YOUR_API_ENDPOINT', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt })
});
return await response.json();
}
- Replace mock responses with real AI responses
🎨 UI Design Principles
- Native VS Code Integration: Uses built-in VS Code components and theme variables
- Theme-Aware: Automatically adapts to user's selected theme (light/dark/high contrast)
- Minimal & Clean: Follows VS Code's design language
- Keyboard-First: Full keyboard navigation support
- Accessible: Proper ARIA labels and semantic HTML
📝 Commands
| Command |
Description |
aiAgent.openChat |
Open the AI chat panel |
aiAgent.generateCode |
Generate code from a prompt |
aiAgent.explainCode |
Explain selected code |
aiAgent.refactorCode |
Get refactoring suggestions |
aiAgent.reviewCode |
Get code quality review |
aiAgent.showDiff |
Show diff preview |
aiAgent.acceptSuggestion |
Accept inline suggestion |
aiAgent.rejectSuggestion |
Reject inline suggestion |
aiAgent.openSettings |
Open extension settings |
🧪 Testing
To test the extension:
- Press
F5 in VS Code to launch Extension Development Host
- Open a code file in the new window
- Try the following:
- Press
Ctrl+Shift+A to open chat
- Type code and wait for inline suggestions
- Select code and right-click for AI actions
- Use Command Palette to access all commands
🤝 Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
📄 License
MIT License - See LICENSE file for details
🔗 Resources
📞 Support
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing documentation
- Review the code comments
Built with ❤️ for the VS Code community