AI Code Snippet RAG VS Code Extension
A VS Code extension that integrates with the AI_CODE_SNIPPET_RAG backend to provide intelligent code queries through VS Code's chat interface.
Features
- Workspace Analysis: Automatically analyzes your workspace, collecting file metadata and samples
- Code Query: Ask questions about your codebase through VS Code's chat interface
- Backend Integration: Connects to the AI_CODE_SNIPPET_RAG backend API
- Context Awareness: Includes active file and selection context in queries
- Caching: Efficient caching of workspace analysis for performance
Requirements
- VS Code 1.85.0 or higher
- Node.js 18+ (for built-in
fetch support)
- AI_CODE_SNIPPET_RAG backend running on
http://localhost:8000 (configurable)
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions view (Ctrl+Shift+X)
- Search for "AI Code Snippet RAG"
- Click Install
From Source (Development)
- Clone or download this extension
- Open the
vscode-extension directory in VS Code
- Run
npm install to install dependencies
- Press
F5 to run the extension in a new Extension Development Host window
Configuration
The extension can be configured through VS Code settings:
aiCodeSnippetRag.serverUrl (default: http://localhost:8000) - Backend server URL
aiCodeSnippetRag.requestTimeoutMs (default: 20000) - Request timeout in milliseconds
aiCodeSnippetRag.maxFiles (default: 5000) - Maximum number of files to analyze
aiCodeSnippetRag.maxBytesPerFile (default: 40000) - Maximum bytes to read per file for sampling
Usage
Commands
- AI Code Snippet RAG: Open AI Code Snippet RAG Chat - Opens the chat panel
- AI Code Snippet RAG: Test Connection - Tests connectivity to the backend
- AI Code Snippet RAG: Rebuild Analysis - Rebuilds the workspace analysis cache
Chat Interface
- Open the chat panel (Command Palette → "AI Code Snippet RAG: Open AI Code Snippet RAG Chat" or use the chat icon)
- Select "Ask AI Code Snippet RAG" as the chat participant
- Type your question about the codebase
- The extension will send your query along with workspace context to the backend
- Results will be displayed in the chat with code snippets and explanations
Backend Setup
Before using the extension, ensure the AI_CODE_SNIPPET_RAG backend is running:
- Start the backend:
docker compose up (in the backend directory)
- Verify the API is accessible:
curl http://localhost:8000/health
- The backend should respond with:
{"status": "healthy", ...}
Note: The backend must implement the /query endpoint at the root level (not under /api/v1) to handle extension requests.
Architecture
The extension performs the following operations:
Workspace Analysis: On activation, analyzes the workspace to collect:
- File inventory (paths, sizes, modification times)
- File samples for text files (truncated to configured limit)
- Language identification
- Workspace fingerprint (SHA256 hash)
Query Processing: When a user sends a chat message:
- Collects active editor context (file path, selection)
- Builds request payload with workspace analysis
- Sends POST request to
/query endpoint
- Renders response as markdown in chat
Caching: Workspace analysis is cached in memory and invalidated when:
- Workspace folders change
- User triggers rebuild command
Security
The extension automatically excludes sensitive files:
.env files
- Files matching
secrets* pattern
- SSH keys (
id_rsa*)
- Certificate files (
*.pfx, *.pem, *.key, *.p12)
- Credential files
Logging
All extension activities are logged to the "AI Code Snippet RAG" output channel:
- Extension activation
- Server configuration
- Analysis progress and results
- Request/response details
- Errors and warnings
View logs: View → Output → Select "AI Code Snippet RAG" from the dropdown
Development
Building
cd vscode-extension
npm install
npm run compile
Testing
- Open the extension in VS Code
- Press
F5 to launch Extension Development Host
- In the new window, open a workspace
- Test commands and chat functionality
Troubleshooting
Connection Issues
- Verify backend is running:
curl http://localhost:8000/health
- Check server URL in settings (AI Code Snippet RAG → serverUrl)
- Check Output panel for detailed error messages
Analysis Issues
- Check
aiCodeSnippetRag.maxFiles setting if analysis is incomplete
- Use "AI Code Snippet RAG: Rebuild Analysis" command to refresh cache
- Check Output panel for analysis errors
Query Issues
- Ensure backend implements
/query endpoint
- Check request timeout setting if queries timeout
- Review Output panel for detailed error messages
License
See LICENSE file for details.