Skip to content

Visual Studio Code as Julia IDE

Eric Neiva edited this page Sep 10, 2021 · 8 revisions

You can follow these steps to set up and work with VS Code as a Julia IDE, using the Julia extension for Visual Studio Code. You need to install VS Code and the extensions julialang.language-julia. Other nice extension is ms-vsliveshare.vsliveshare for real-time remote collaborative development.

The instructions were written for VS Code version 1.47.2 and the 0.17.7 version of the extension.

1. Install and configure the IDE

Follow the Getting started section of the README page of the julia-vscode github page

2. Go through the IDE features

Read the Features section of the README page (e.g. Code navigation)

3. Set up Julia environment

  • Go to File -> Open Folder... and open your Julia project folder
  • If the extension has been correctly installed, a window prompt will suggest to set the project folder as the current Julia environment. Alternatively, you can change the current environment by typing CTRL+Shift+P and executing the command Julia: Change Current Environment -> (pick a folder) and choose the project folder. Any of these two actions generates a .vscode folder in the project with a settings.json setting the Julia environment
  • If the field Julia env: at the lower bar is populated with your project name, the environment has been correctly set. You can also check it by CTRL+Shift+P Julia: Start REPL and entering the Pkg REPL by pressing ] from the Julia REPL
  • Note that the working directory of the Julia REPL session is the one of your current folder or workspace.

4. Set up Gridap format style

According to the contributing page, we recommend that you have the following options in your Julia syntax specific settings.

To modify these settings open your VS Code Settings with CMD+, (Mac OS) or CTRL+, (other OS), and add to your settings.json:

{
    "[julia]": {
        "editor.detectIndentation": false,
        "editor.insertSpaces": true,
        "editor.tabSize": 2,
        "files.insertFinalNewline": true,
        "files.trimFinalNewlines": true,
        "files.trimTrailingWhitespace": true,
        "editor.rulers": [80],
    },
    "julia.execution.resultType": "inline",
}

The option "julia.execution.resultType": "inline" is not mandatory, but highly suggested if you are moving to VSCode from Juno-Atom.

5. Learn how to run the debugger

Watch the video from JuliaCon 2020. This video can also be interesting to know the status and plan as August 2020.

6. Choose a development workflow

VS Code can readily support both the REPL based workflow or the Juno based workflow.

For the REPL-based case, the extension can load Revise.jl on startup for you (go to the extension settings and activate the field Julia: Use Revise).

For the Juno-based case, it may be helpful to watch this (outdated) Juno video to grasp the dynamics of the workflow and read the Running code section of the extension documentation.

7. Native notebook support for Jupyter notebooks

The Julia VS Code extension allows you to run Julia-code Jupyter notebooks in VS Code, without using IJulia. Please, see how here. There are two things you should do that are not mentioned in the video: (1) Also install the python extension and (2) Check the option "Notebook Controller" in the Julia VS Code extension.

8. Shared sessions of VS Code

With the Live Share extension for VS Code, we are able to simultaneously work on (and execute) Gridap code as though we are in a Google Docs. The setup is relatively simple, the usage is intuitive and the performance seems good (e.g. very little lag). The extension also comes with an extra add-on for an audio call (which works pretty well for 1-on-1).

Remarks

  • Minor glitches with shared REPL sessions
  • Displaying PDFs in the shared session (maybe the tex extension works)
  • Sharing the workspace variables of the shared REPL session
  • Opening a shared debugging session
  • The terminal and REPL are in read only mode by default. The host needs to change it to read/write mode if you want the other members to be able to execute
  • You need to trust the session you join, in order to use some functionalities (e.g. audio call)

9. Further references