Venv Aware Python — VS Code Extension
A VS Code extension with a bundled Python indexer that provides version‑accurate code completions and diagnostics based on your currently active Python virtual environment (venv). No additional setup required!
🎉 New in v0.2.0: Bundled Edition
Zero setup complexity - The extension now includes a complete bundled indexer:
- ✅ No external dependencies - Everything included in the extension
- ✅ No manual installation - Just install the extension and use it
- ✅ Enhanced stability - Crash protection and subprocess isolation
- ✅ Fixed issues - Resolved introspection and memory management problems
Features
🎯 Version-Accurate Completions
- Only suggests symbols that exist in your installed package versions
- Automatically adapts to different virtual environments
- Prioritizes symbols from your actual installed packages
⚠️ Smart Diagnostics
- Warns when you use symbols not available in your current environment
- Suggests similar symbols when you make typos
- Provides quick fixes for common issues
🔄 Automatic Environment Detection
- Integrates with the official Python extension when present
- Works without a hard dependency by using configured/system Python
- Automatically detects interpreter changes and can rebuild the index
🚀 Fast Symbol Indexing
- Safe AST-based parsing with subprocess isolation
- Enhanced introspection with memory protection
- Incremental caching for faster rebuilds
Installation (dev)
- Install the Python indexer locally (optional when using published extension):
cd ../indexer
pip install -e .
- Build the extension:
npm install
npm run compile
- Launch Extension Development Host:
- Press
F5
in VS Code or “Debug: Start Debugging”
Usage
Initial Setup
- Open a Python project with a virtual environment
- The extension will automatically detect your Python interpreter
- Choose "Build Index" when prompted to create the symbol index
- Start coding with version-accurate completions!
Commands
Access these commands via Command Palette (Ctrl+Shift+P
):
- Venv Aware: Rebuild Index - Manually rebuild the symbol index
- Venv Aware: Show Installed Package Symbols - Browse available symbols
- Venv Aware: Show Index Statistics - View index information
- Venv Aware: Switch Interpreter... - Change Python interpreter
Configuration
Configure the extension in VS Code settings:
{
"venvAware.indexOnActivate": true,
"venvAware.hideUnknownSymbols": false,
"venvAware.maxDocLength": 200,
"venvAware.enableDiagnostics": true,
"venvAware.indexingMethod": "both",
"venvAware.logLevel": "info"
}
Settings Reference
Setting |
Type |
Default |
Description |
indexOnActivate |
boolean |
true |
Automatically rebuild index when Python interpreter changes |
hideUnknownSymbols |
boolean |
false |
Hide symbols not found in the virtual environment index |
maxDocLength |
number |
200 |
Maximum length of documentation strings in completions |
enableDiagnostics |
boolean |
true |
Enable diagnostics for unknown symbols |
indexingMethod |
string |
"both" |
Method to use for symbol indexing ("both" , "ast-only" , "introspection-only" ) |
logLevel |
string |
"info" |
Log level for extension output ("error" , "warn" , "info" , "debug" ) |
How It Works
Environment Detection
The extension prefers the official Python extension to detect:
- Current Python interpreter path
- Virtual environment activation/changes
If the Python extension is not present, it falls back to:
python.defaultInterpreterPath
/ python.interpreterPath
- Probing system
python3
/python
Symbol Indexing
When you switch environments or rebuild the index:
- Package Discovery: Scans
site-packages
directories
- Symbol Extraction: Uses safe AST parsing and optional isolated introspection
- Index Creation: Generates
.venv-index/venv_symbols.index.json
at the workspace root
- File Watching: Monitors the index file and reloads on change
Completion Enhancement
The extension enhances VS Code's built-in Python completions by:
- Filtering symbols based on your installed versions
- Prioritizing symbols from your environment
- Adding detailed documentation from your packages
Diagnostics
Real-time analysis provides:
- Warnings for unavailable symbols
- Suggestions for similar symbols
- Quick fixes for common mistakes
Example Scenarios
Scenario 1: Version-Specific APIs
import numpy as np
# With numpy 1.21.0 installed:
np.typing.NDArray # ✅ Available, shows completion
# With numpy 1.20.0 installed:
np.typing.NDArray # ❌ Warning: not available in this version
Scenario 2: Environment Switching
Environment A (pandas 1.5.0):
df.to_markdown() # ✅ Available
Switch to Environment B (pandas 1.3.0):
df.to_markdown() # ❌ Warning: requires pandas >= 1.4.0
Scenario 3: Typo Detection
import requests
response = requests.gest('https://api.example.com') # Typo
# 💡 Quick fix: Did you mean 'get'?
Development
Project Structure
src/
├── extension.ts # Main extension entry point
├── activation/
│ └── pyEnv.ts # Python environment detection
├── index/
│ ├── loader.ts # Index loading and management
│ └── schema.ts # Type definitions
├── features/
│ ├── completions.ts # Completion provider
│ ├── diagnostics.ts # Diagnostic provider
│ └── commands.ts # Extension commands
└── utils/
└── log.ts # Logging utilities
Building
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch for changes
npm run watch
# Run tests
npm test
# Package extension
npm run package
Testing
- Launch Extension Development Host (
F5
)
- Open a Python project
- Test completions and diagnostics
- Check output logs for debugging
Debugging
Enable debug logging in settings:
{
"venvAware.logLevel": "debug"
}
View logs in VS Code Output panel: "Venv Aware Python"
Troubleshooting
Index Not Building
Check that venv-indexer
is installed:
venv-indexer --help
Verify Python interpreter is detected:
- Run "Venv Aware: Show Index Statistics"
- Check the interpreter path
Check extension logs for errors
Completions Not Working
- Ensure index is built and loaded
- Check that you're in a Python file (
.py
)
- Verify the symbol exists in your environment:
venv-indexer show package_name
Use AST-only indexing for faster builds:
{
"venvAware.indexingMethod": "ast-only"
}
Clear the package cache:
venv-indexer clear
Requirements
- VS Code 1.74.0 or higher
- Python 3.8 or higher
- Official Python extension (
ms-python.python
)
- VenvIndexer package installed
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE for details.