New Mojo VS Code extension

We have a brand-new Mojo VS Code extension that has been rewritten from the ground up to provide a much better experience. Oh, and it’s now open source!

This new VS Code extension has been re-architected to fit how Mojo is distributed today. It detects the Mojo Language Server Protocol (LSP) server that’s present in either a Python virtual environment or a Pixi environment with Mojo installed. It detects the environment to use when you open the directory for your project, making sure that the version of Mojo used in the LSP is the same as when building your project.

This means that we no longer need to have two Mojo VS Code extensions, and will be sunsetting the nightly VS Code extension in favor of the one main Mojo extension. That should hopefully reduce some of the confusion people have experienced when seeing the two extensions, as well as when forgetting to turn one on and the other off.

This VS Code extension has replaced the default Mojo VS Code extension on the VS Code marketplace. We recommend switching to the main Mojo extension, and then installing the update to get this new version. You can freely uninstall the previous Mojo (nightly) extension, as that is no longer needed. This should also be up soon on OpenVSX to support other IDEs like Cursor.

If you want to try out bleeding-edge builds, a new .vsix extension is built on each merged pull request to the mojo-vscode repository. To download the extension, go to the Actions tab at the top of the repo, click on the corresponding “Build extension” action, and then scroll to the bottom to download the zip archive of the .vsix. Unzip this archive and in VS Code you can then go to extensions, choose the three-dot menu at the top and pick “Install from VSIX…”

One thing to be aware of with this new extension: it 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.

If you run into significant issues while trying out this new extension, please feel free to file an issue or comment in this thread. I will note that crashes of the LSP, syntax higlighting problems, and similar issues generally aren’t related to the extension itself but to the Mojo LSP. We have efforts underway to make significant improvements to that as well, in parallel to this new extension.

14 Likes

Any compatibility concerns with using this in cursor? Specifically the Python extension req part? I could always guinea pig this and make an issue if I have problems.

It has seemed to work well for me in Cursor, but if you run into issues, please let us know. Worst case, you can re-install our old Mojo nightly extension that we have on OpenVSX right now.

1 Like

The new extension doesn’t seem to be able to find the environment installed by following the default setup in the modular repo. I think other stdlib contributors will run into similar issues.

Is it still unable to find the Pixi environment for the modular repo if you invoke the Python: Select Interpreter command in VS Code and manually choose the .pixi environment for the repository?

That works like a charm. Thanks!

1 Like

Thanks for all of the work on this! I’ve tested on OSX and on WSL so far and definitely works better than the older version(s). I’m having issues with the debug though, now I never tested this with the old version so not sure if this is just a user error or not.

When I attempt to debug a mojo file I get the following error:

Failed to run preInitCommands commands. See the Debug Console for more details.

Then in the debug console I have:

Running preInitCommands:
(lldb) plugin load $CONDA_PREFIX/lib/libMojoLLDB.*
error: no such file

On OSX I’m seeing basically the same error around this lldb plugin. I haven’t touched the launch.json file yet.

I’d appreciate any tips to get this working, thanks!

1 Like

Please create issues in the mojo-vscode repo for better tracking

1 Like

Sounds good, just created an issue. Hate to distract the modular team if this is just a user error on my part. Thanks though.

2 Likes

The new Mojo extension is now live on the main VS Code marketplace. We’re working to get it up on Open VSX, as well. If you are on VS Code, you should be able to update the main Mojo extension and get this new one. You can then safely uninstall the Mojo nightly extension, as its functionality is now covered by this unified extension.

1 Like