GenLayer VS Code Extension
Official VS Code extension for developing GenLayer intelligent contracts with Python, featuring real-time linting, code intelligence, and deployment tools.
Features
🔍 Real-time Linting
- Automatic validation of GenVM contract files on save and edit
- Inline diagnostics with error squiggles and hover information
- Comprehensive rule checking for GenVM-specific syntax and patterns
📝 Code Intelligence
- Smart snippets for common GenVM patterns
- Syntax highlighting for GenVM-specific types and decorators
- Auto-completion for GenVM types and decorators
⚙️ Configurable Rules
- Rule filtering - enable/disable specific linting rules
- Severity levels - customize error/warning/info levels
- Workspace settings - per-project configuration
Installation
Prerequisites
Python 3.8+ with the GenVM linter package installed:
pip install genvm-linter
VS Code 1.74.0+
Install Extension
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "GenVM Linter"
- Click Install
Manual Installation
- Download the
.vsix file
- In VS Code, press Ctrl+Shift+P
- Type "Extensions: Install from VSIX"
- Select the downloaded
.vsix file
Usage
Automatic Linting
The extension automatically detects GenVM contract files by looking for:
- Files with the GenVM magic comment:
# { "Depends": "py-genlayer:test" }
- Python files with "contract", "genvm", or "genlayer" in the filename
Manual Commands
Access these commands via the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on Mac):
- GenLayer: Lint Current File - Lint the active Python file for GenLayer compliance
- GenLayer: Lint Workspace - Lint all GenLayer contracts in the workspace
- GenLayer: Show GenLayer Output - Show the GenLayer output channel with diagnostic logs
- GenLayer: Debug - Display debug information about the extension and linter
- GenLayer: Test Lint - Test the linter with a sample contract to verify setup
- GenLayer: Install Dependencies - Install required Python packages (genvm-linter, mypy)
- GenLayer: Create Contract - Create a new intelligent contract from a template
- GenLayer: Deploy Contract - Deploy the current contract to a GenLayer network
Code Snippets
Type these prefixes and press Tab:
genvm-contract - Complete contract template
genvm-magic - Magic comment
genvm-import - GenLayer import
genvm-view - Public view method
genvm-write - Public write method
genvm-dataclass - Storage dataclass
genvm-treemap - TreeMap field
genvm-dynarray - DynArray field
Configuration
Configure the extension through VS Code settings:
{
"genlayer.linting.enabled": true,
"genlayer.linting.severity": "warning",
"genlayer.linting.showSuggestions": true,
"genlayer.linting.excludeRules": [],
"genlayer.python.interpreterPath": "python3"
}
Available Settings
| Setting |
Type |
Default |
Description |
genlayer.linting.enabled |
boolean |
true |
Enable/disable GenLayer linting |
genlayer.linting.severity |
string |
"warning" |
Minimum severity to show (error, warning, info) |
genlayer.linting.showSuggestions |
boolean |
true |
Show fix suggestions in diagnostics |
genlayer.linting.excludeRules |
array |
[] |
Rules to exclude from linting |
genlayer.python.interpreterPath |
string |
"python3" |
Path to Python interpreter |
Example Workspace Settings
{
"genlayer.linting.enabled": true,
"genlayer.linting.severity": "error",
"genlayer.linting.excludeRules": ["genvm-magic-comment"],
"genlayer.python.interpreterPath": "/usr/local/bin/python3.11"
}
Validation Rules
The extension validates the following GenVM-specific rules:
Structure Rules
- ✅ Magic comment on first line
- ✅ GenLayer import statement
- ✅ Single contract class extending
gl.Contract
Type System Rules
- ✅ Sized integers in storage (
u256, u64, etc.)
- ✅ GenVM collections (
TreeMap, DynArray)
- ✅ Correct return types (
int not u256)
- ✅ Dataclass storage decorators
Decorator Rules
- ✅ Proper
@gl.public.view/@gl.public.write usage
- ✅ No decorators on constructors
- ✅ State modification detection
Example

# { "Depends": "py-genlayer:test" }
from genlayer import *
class TokenContract(gl.Contract):
balance: u256 # ✅ Correct: sized integer for storage
owner: Address
def __init__(self, initial_balance: int):
self.balance = initial_balance
self.owner = gl.message.sender_address
@gl.public.view # ✅ Correct: view decorator for read-only
def get_balance(self) -> int: # ✅ Correct: int return type
return self.balance
@gl.public.write # ✅ Correct: write decorator for state changes
def transfer(self, to: str, amount: int):
if amount > self.balance:
raise gl.Rollback("Insufficient balance")
self.balance -= amount
Troubleshooting
Extension Not Working
- Check that Python is installed and accessible
- Verify genvm-linter package is installed:
pip show genvm-linter
- Check the GenVM Output channel for error messages
- Ensure Python interpreter path is correct in settings
Linting Not Triggering
- Verify file contains GenVM magic comment
- Check that linting is enabled in settings
- Save the file to trigger linting
- Check Output → GenVM Linter for error messages
Python Path Issues
- Set absolute path in
genlayer.python.interpreterPath
- Use the Python interpreter where genvm-linter is installed
- Test manually:
python3 -m genvm_linter.cli --version
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test the extension
- Submit a pull request
Development Setup
git clone https://github.com/genlayerlabs/vscode-extension.git
cd vscode-extension
npm install
npm run compile
Press F5 in VS Code to launch Extension Development Host.
License
MIT License - see LICENSE for details.