odoo-shortcuts

CodeLens

CodeLens provides contextual actions directly in the editor, showing useful links above relevant classes and methods.

🎯 Features

CodeLens automatically appears above:

πŸ“ Python Models

When you open a Python file with Odoo models, you’ll see links above each class:

class SaleOrder(models.Model):  # ← [Create Views] [Create Report] [Import Security]
    _name = 'sale.order'
    _description = 'Sales Order'

Available Actions

Action Description Alternative Command
Create Views Generates XML file with views Odoo Shortcuts: Create Views
Create Report Generates QWeb report Odoo Shortcuts: New Report
Import Security Creates access rules Odoo Shortcuts: Import Security Model Access
Create Inherit View Generates inherited views Odoo Shortcuts: Create Inherit Views

🎨 OWL Components

For OWL components, CodeLens shows:

/** @odoo-module **/
export class MyComponent extends Component {  // ← [OWL Documentation]
    static template = "my_module.MyComponent";
}

OWL Actions

Action Description
OWL Documentation Opens OWL documentation in webview

βš™οΈ Configuration

Enable/Disable CodeLens

{
  "odooFile.codelens.enabled": true  // or false to disable
}

Language Configuration

CodeLens automatically activates for:

πŸš€ Usage

How to Use CodeLens

  1. Open a file with Odoo models or OWL components
  2. Wait a moment (CodeLens loads asynchronously)
  3. Click on the links that appear above classes
  4. Follow the command instructions

CodeLens in Action

Complete Example

# Open models/sale_order.py

class SaleOrder(models.Model):  
    # [Create Views] [Create Report] [Import Security]  ← Appears here
    
    _name = 'sale.order'
    _description = 'Sales Order'
    
    name = fields.Char(string='Name')
    partner_id = fields.Many2one('res.partner', string='Customer')

You click [Create Views]:

  1. Select Odoo version
  2. Generates views/sale_order_views.xml
  3. Updates __manifest__.py
  4. Opens generated file

🎨 Appearance

CodeLens appears as light gray text above definitions:

CodeLens Appearance

[Create Views] [Create Report] [Import Security]
class MyModel(models.Model):

Color and style follow the VS Code theme.

πŸ› Troubleshooting

CodeLens doesn’t appear

  1. Verify the file is detected as Python
  2. Check that odooFile.codelens.enabled is true
  3. Wait a few seconds (loads asynchronously)
  4. Restart VS Code if necessary

CodeLens appears in wrong files

CodeLens uses heuristics to detect Odoo models:

Slow performance

If CodeLens slows down the editor:

  1. Temporarily disable: "odooFile.codelens.enabled": false
  2. Close unrelated large files
  3. Consider splitting very large files

πŸ’‘ Tips

1. Quick Use

CodeLens is the fastest way to generate code related to a model.

2. Visual Context

Links only appear when relevant, keeping the editor clean.

3. Multi-model

If a file has multiple models, each will have its own CodeLens links.

πŸ“Š Comparison with Commands

Feature CodeLens Commands
Speed One click Command palette
Context Model specific General
Discovery Automatic visual Memorize shortcuts
Flexibility Current model Any model

Recommendation: Use CodeLens for the current model, commands for other models.

πŸ”§ Technical Implementation

CodeLens works through:

  1. CodeLens Provider - Registers provider for Python/JS
  2. AST Analysis - Parses code to find classes
  3. Symbol Resolution - Identifies Odoo models and OWL components
  4. Command Generation - Creates links for each case

Analysis is done in real-time as you edit.


Next: XPath Tools