The AMPL VS Code Extension provides language support for AMPL, including syntax highlighting and integration with the AMPL runtime.
Enjoy full syntax highlighting for .mod, .run, and .dat files. Note that highlighting for .datfiles is simplified, to support big file sizes.
Quickly run .mod or .run files directly from the editor.
Select any entity or expression in the editor to display them in the AMPL runtime.
Most used AMPL commands have keyboard shortcuts and can be accessed by the command palette:
run- send current file to AMPLreset- reset the current sessionsolve- solve the modeldisplay expression- choose an arbitrary expression and evaluate it in AMPL
AMPL projects often consist of several files, such as a main model file, some data files, and a script listing the files to include. This extension supports multi-file workflows: you can select a root file (the main entry point for parsing and running), and the extension will ensure that all relevant files are parsed and available to the language server. This enables features like go-to-definition, diagnostics and workspace symbols to work seamlessly across your entire project, not just the currently open file.
Use the command AMPL: select files to parse to choose the root file to parse; in case of multiple configurations, they can be switched to/from by AMPL: select launch configuration.
Use CTRL/Cmd + P to see and search the list of symbols in the current workspace.
- Hover over an entity declared in the current file (or workspace) to see its declaration
- Right click or press F12 for "go to definition"
- Tokenized syntax highlighting to support distinction for functions and variables.
Get a list of symbols in the current file in the outline view
Errors are higlighted and listed in the "Problems" window in VS code. Note that the language server is currently under development, therefore some language features might be missing; in case valid constructs are flagged as errors, please disable diagnostic.
| Command | Keybinding (Mac) | Keybinding (Windows/Linux) |
|---|---|---|
| Run File | Cmd+Shift+Enter |
Ctrl+Shift+Enter |
| Display Entity | Cmd+Shift+L |
Ctrl+Shift+D |
| Reset | Cmd+Shift+R |
Ctrl+Shift+R |
| Solve | Ctrl+Shift+L |
Ctrl+Shift+L |
- Install the extension from the VS Code Marketplace.
- If AMPL is not on the system path, configure the path to the AMPL binary in the settings.
| Setting | Description |
|---|---|
AMPL.Runtime.pathToAMPLBinary |
Path to the AMPL binary. If empty, the extension will look for it in system paths. |
AMPL.Runtime.pathToJRE |
Path to the Java Runtime Environment (min Java 11). If empty, the extension will look in the environment variable JAVA_HOME and then in the system paths. |
AMPL.Runtime.changeDirectoryOnRun |
Change the working directory of AMPL to the directory of the file being run. |
AMPL.LanguageServer.enableLanguageServer |
Enable or disable the language server for AMPL files. |
AMPL.LanguageServer.trace.server |
Trace the communication between VS Code and the AMPL language server. |
AMPL.LanguageServer.diagnosticsEnabled |
Enable or disable error highlighting for AMPL files. Requires the language server. |
AMPL.Advanced.enablePsuedoTerminal |
Enable or disable the advanced pseudoterminal. Has more features but can be unstable. |
AMPL.Advanced.enableAdvancedCommands |
Enable advanced and beta features like custom configuration and file selection commands. |
File questions, issues, or feature requests for the extension by:
- Emailing us at [email protected]
- Filing an issue on GitHub Issues
This extension is licensed under the MIT License.




