This VS Code extension from the Modular team adds support for the Mojo programming language.
- Syntax highlighting for
.mojo
and.🔥
files - Code completion
- Code diagnostics and quick fixes
- Full LSP experience for doc string code blocks
- Go to symbol
- API docs on hover
- Code formatting
- Run Mojo file
- Install the MAX SDK.
- Open the folder you installed MAX in.
- Open any
.mojo
or.🔥
file.
The extension relies on the Python extension for locating your Python environment. In some cases, this appears to default to your globally-installed environment, even when a virtual environment exists. If the Mojo extension cannot find your SDK installation, try invoking the Python: Set Project Environment
command and selecting your virtual environment.
A fully featured LLDB debugger is included with Mojo. You can press the down
arrow next to the ▶️
button in the top right of a Mojo file, and select
Debug Mojo File
:
The default key is F5
, and you can rebind the related hotkeys in Preferences:
Open Keyboard Shortcuts > Debug: Start Debugging
To trigger a completion press ctrl + space
, pressing ctrl + space
again will
bring up doc hints:
Rebind the hotkey in Preferences: Open Keyboard Shortcuts > Trigger Suggest
Hover over a symbol with your cursor for doc hints. The default hotkey
to trigger it in macOS is ⌘ + k
, ⌘ + i
or ctrl + k
, ctrl + i
in Linux
and Windows:
Rebind the hotkey in Preferences: Open Keyboard Shortcuts >
Show or Focus Hover
Mojo provides function overloading, so you need a way to scroll through the
multiple signatures available. You can bring this up with the hotkey
⌘ + shift + space
in macOS or ctrl + shift + space
in Linux or Windows.
Rebind related hotkeys in Preferences: Open Keyboard Shortcuts >
Trigger Parameter Hints
Code diagnostics are indicated with an underline on the code and details appear
when you hover. You can also see them in the PROBLEMS
tab and use
Go to Next Problem in Files
to quickly cycle through them:
Rebind related hotkeys in Preferences: Open Keyboard Shortcuts >
Go to Next Problem...
Tip: Also try the Error Lens
extension (not associated with Modular),
which will display the first line of the diagnostic inline, making it easier
to quickly fix problems.
Unique to Mojo, you get a full LSP experience for code blocks inside doc strings, with all the features mentioned here including completions and diagnostics:
You can quickly jump to a symbol in the file with ⌘ + shift + o
in macOS or
ctrl + shift + o
in Linux and Windows.
This also enables the outline view in the explorer window.
Rebind the hotkey in Preferences: Open Keyboard Shortcuts >
Go to Symbol in Editor
If there is an available quick fix with the code diagnostic, click
the lightbulb icon or use the default hotkey ctrl + .
for a list of options:
Rebind the hotkey in Preferences: Open Keyboard Shortcuts >
Quick Fix...
The extension provides a set of actions on the top-right of a Mojo file to run
the active file, which by default are under a small ▶️
button up the
top-right of the editor:
These actions are also available in the command palette and under the Mojo
submenu in the File Explorer when right-clicking on Mojo files:
You may bind hotkeys to any of the actions listed here. For example, to bind a
hotkey for the "Run Mojo File" action, open preferences, then select
Keyboard Shortcuts > Mojo: Run Mojo File
.
This executes the current Mojo file in a terminal that is reused by other invocations of this same action, even if they run a different file.
This executes the current Mojo file in a dedicated terminal that is reused only by subsequent runs of this very same file.
From the command palette run Format Document
or tick the setting
Format on Save
:
The extension may crash and produce incorrect results periodically, to fix this
from the command palette search for Mojo: Restart the extension
Bind a hotkey in Preferences: Open Keyboard Shortcuts >
Mojo: Restart the extension