OPL Language Support for Visual Studio Code
Syntax highlighting and language support for IBM ILOG CPLEX Optimization Programming Language (OPL) files in Visual Studio Code.
Features
This extension provides comprehensive syntax highlighting and execution support for:
.mod files - OPL Model files containing optimization models
.dat files - OPL Data files containing data definitions and database connections
- Run OPL Models - Execute
.mod files directly from VS Code with F5
Editor Features
- Bracket Matching: Automatic matching for
{}, [], (), <>, #[]#, #<>#
- Auto-Closing Pairs: Automatically closes brackets, quotes, and special OPL constructs
- Comment Toggling: Use
Ctrl+/ (or Cmd+/ on Mac) to toggle line comments
- Code Folding: Fold code blocks and regions
- Smart Indentation: Automatic indentation based on OPL syntax
Installation
From VSIX (Local Installation)
- Download the
.vsix file
- Open VS Code
- Go to Extensions view (
Ctrl+Shift+X or Cmd+Shift+X)
- Click the
... menu at the top of the Extensions view
- Select "Install from VSIX..."
- Choose the downloaded
.vsix file
From Source
- Clone this repository
- Open the folder in VS Code
- Press
F5 to launch a new VS Code window with the extension loaded
Usage
Once installed, the extension automatically activates when you open .mod or .dat files. The syntax highlighting will be applied based on your current color theme.
Running OPL Models
You can execute OPL models directly from VS Code:
- Press F5 while editing a
.mod file to run it with OPL
- The extension will automatically:
- Save the file if it has unsaved changes
- Look for a corresponding
.dat file with the same name
- Execute
oplrun with both the .mod and .dat files (if .dat exists)
- Display the output in the integrated terminal
OPL Projects View
The extension provides an OPL Projects view in the VS Code sidebar for managing .oplproject configuration files. This view allows you to organize and execute your OPL projects with their associated model and data files.
Key Features:
- View all
.oplproject files in your workspace in a tree structure
- Run configurations directly from the view by clicking the play button (▶️) next to any config
- Delete configurations by right-clicking on any config and selecting "Delete Configuration"
- Quick access to your project configurations without navigating through the file system
To activate the OPL Projects view:
- Open the VS Code sidebar (
Ctrl+B or Cmd+B)
- Look for the OPL Projects icon in the Activity Bar (left side)
- Click on it to expand the view and see all
.oplproject files in your workspace
The view automatically refreshes when you add, modify, or delete .oplproject files in your workspace.
Configuration
Set the path to your oplrun executable in VS Code settings:
- Open Settings (
Ctrl+, or Cmd+,)
- Search for "OPL"
- Set OPL: Oplrun Path to your
oplrun executable path
Default: oplrun (assumes it's in your system PATH)
Example paths:
- Windows:
C:\Program Files\IBM\ILOG\CPLEX_Studio221\opl\bin\x64_win64\oplrun.exe
- Linux/Mac:
/opt/ibm/ILOG/CPLEX_Studio221/opl/bin/x86-64_linux/oplrun
Alternatively, add this to your settings.json:
{
"opl.oplrunPath": "C:\\Program Files\\IBM\\ILOG\\CPLEX_Studio221\\opl\\bin\\x64_win64\\oplrun.exe"
}
Example Files
Check the following folders for sample OPL files:
Known Limitations
- Semantic highlighting is not yet implemented (context-aware highlighting)
- Some complex nested structures may not be perfectly highlighted
- Execute blocks contain embedded code that uses basic highlighting
- No IntelliSense or code completion yet
- No error detection or diagnostics yet
Resources
License
Apache License 2.0 - See LICENSE file for details